Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to redirect to a JSP(with different param values) with POST method?  RSS feed

 
Chandima Panditha
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to call a JSP page with different values (in a loop where CustID=1, CustID=2, etc) with the "POST" method. I need to do what's below html code (first 3 lines) is doing using JSP. The reason why I need to to in a JSP (or Servlet or an Applet) is, I need to loop through few CustIDs, for ex CustID=1, CustID=2, etc.
Any help is really appreciated...
Thanks
Chandi


customer.html
<form name="cust_details"
action="http://localhost:8080/customer/displayItems.jsp?CustID=1"
method="post">

<table border="0">
<tr>
<td><div align="right"> Email : </div></td>
<td ><input name="username" type="text" > </td>
</tr>
<tr>
<td><div align="right"> Password: </div></td>
<td><input name="password" type="password" ></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input name="Submit" type="submit" value="Login">
</div></td>
</tr>
</table>
 
Marty Hall
Author
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to call a JSP page with different values (in a loop where CustID=1, CustID=2, etc) with the "POST" method. I need to do what's below html code (first 3 lines) (ie a FORM with METHOD=POST) is doing using JSP.

Hmm. Do you need to see the output of the JSP? Or just invoke the URL (where, presumably, the JSP performs some side effect that you want)?
If the latter, this can be done using a URLConnection with setDoOutput(true) and a Writer or OutputStream to send the data. Don't forget to use URLEncoder.encode on the data before you send it. Of course you would do this from a servlet or regular application, not a JSP, though.
I have an example that walks you through this in Section 17.5 of Core Servlets and JavaServer Pages, which is online in PDF for free access at http://pdf.coreservlets.com/. That example is in the context of an applet invoking a URL, but the code is the same for any Java program.
Cheers-
- Marty
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!