Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP : PARAMS action

 
Jaggi Kunal
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to retrieve Parameters in a JSP page which are set by another JSP page.
Following are the two code snippets :
<%-- Param1.jsp --%>
<HTML>
<HEAD><HEAD>
<BODY>
<jsp arams>
<jsp aram name="name" value="Yash" />
<jsp aram name="age" value="23" />
<jsp aram name="eyes" value="black" />
</jsp arams>
<A HREF="/Param2.jsp">Click Here</A>
</BODY>
</HTML>
<%-- Param2.jsp --%>
<HTML>
<HEAD><HEAD>
<BODY>
<%
out.println("<b>"+request.getParameter("name")+"</b>");
out.println("<b>"+request.getParameter("age")+"</b>");
out.println("<b>"+request.getParameter("eyes")+"</b>");
%>
</BODY>
</HTML>
I am getting a compilation error when I access Param1.jsp using http://localhost:8080/Para1.jsp. I am using Tomcat 4.1.12.

Regards,
Kunal Jaggi
SCJP
[ April 01, 2003: Message edited by: Jaggi Kunal ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you not think that it might be a tad more useful to actually post the compilation error that you are getting?
Also, if you want to pass request parameters to the next request, you'll either need to encode them as part of the URL (on the the query string), or create a form in which they are posted using hidden parameters.
hth,
bear
[ April 01, 2003: Message edited by: Bear Bibeault ]
 
Mark Bensing
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To expand on what Bear has said, there is no <jsp:params> action in JSP. <jsp:param> can be used within the <jsp:include> and <jsp:forward> actions to add parameters to the request as follows:

Mark
[ April 01, 2003: Message edited by: Mark Bensing ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark is correct on that. I missed the <jsp:params> as the smiley faces got in the way (you do know you can turn those off when posting code, no?).
And that will work fine to include a JSP in another. To pass along a request parameter to a completely separate request however, you are going to have to bite the bullet and generate a URL complete with the parameters in the query string (don't forget to URL-encode the values), or do the hidden form thing.
hth further,
bear
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic