• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

<jsp:forward> with params

 
Veeresh Hubballi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<jsp:forward page"/TestServlet">
<jsp:param value="sort" name="action"/>
</jsp:forward>


Why request.getParameter("action") gives me null in TestServlet. :confused:
 
Marc Pfaller
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Veeresh Hubballi,

you forgot the equal sign in line 1 after the page Attribut. Then it should work.

<jsp:forward page="/TestServlet">




 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65128
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A forward simply forwards the existing request to another resource. It does not create a new request, so you can't add params to it.

If you have data you need to pass along, simply put that data in request scope.
 
Marc Pfaller
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:A forward simply forwards the existing request to another resource. It does not create a new request, so you can't add params to it.

If you have data you need to pass along, simply put that data in request scope.


Hello Bear Bibeault,

i tested the jsp Code from Veeresh Hubballi with NetBeans in the index.jsp and created a TestServlet
in which i read the Parameter: String myAction = request.getParameter("action");
and output it.
It outputs the Parameter Value normally.

jsp:forward with jsp:param no Problem.

OracleDocs also gives similar examples:
http://docs.oracle.com/cd/B12314_01/web.904/b10320/genlovw.htm

" As with jsp:include, you can also have an action body with jsp:param tags, as shown in the second of the following examples:

<jsp:forward page="/templates/userinfopage.jsp" />

or:

<jsp:forward page="/templates/userinfopage.jsp" >
<jsp:param name="username" value="Smith" />
<jsp:param name="userempno" value="9876" />
</jsp:forward>"
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65128
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, it must do that beneath the covers. Good info.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic