views:

176

answers:

1

I have a question about how to allow my jsp page to issue a post command to the server, and still have the browser fallow the re direction of the posted page.

Here are the code snipets:

code that does the post (this is inside a jsp file):

HttpClient client = new DefaultHttpClient();
client.getParams().setParameter("SUBMITTED", "submitted");
client.getParams().setParameter("xxxxxxxx", purchaser.getemail());
client.getParams().setParameter("xxxxxxxx", purchaser.getsuject());

HttpPost method = new HttpPost(url+"process.jsp");
client.execute(method); 

here is a snipet of process.jsp

if (person.getStatus() == person.ACTIVE)
  response.sendRedirect("Account.jsp);
else if (person.getStatus() == person.ERROR)
  response.sendRedirect("Error.jsp);

I would like the browser to the fallow/goto the redirect from the process.jsp. Does anyone know a tutorial that would help me or Am I going about this the wrong way.

+1  A: 

You're indeed going the wrong way with this. As with any "raw Java code inside a JSP" this logic belongs in a real Java class, not in a JSP file. Create a Servlet which does this and let it in turn redirect/forward the request to the JSP file of interest.

JSP is a view technology and is actually part of the response body. If you're trying to change the response's halfway a JSP, you'll only end up with IllegalStateException: response already committed.

Further, the whole functional requirement is unclear from the question. I have the impression that the both JSP files are running in the same environment and then the whole HttpClient approach is wrong. Start learning a bit more about servlets. This is a good starting point.

BalusC