This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JSP and the fly likes <jsp:forward> with params Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "<jsp:forward> with params" Watch "<jsp:forward> with params" New topic
Author

<jsp:forward> with params

Veeresh Hubballi
Greenhorn

Joined: Apr 10, 2011
Posts: 2
<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

Joined: Feb 28, 2013
Posts: 3
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

Joined: Jan 10, 2002
Posts: 61315
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Marc Pfaller
Greenhorn

Joined: Feb 28, 2013
Posts: 3
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

Joined: Jan 10, 2002
Posts: 61315
    
  66

Ah, it must do that beneath the covers. Good info.
 
GeeCON Prague 2014
 
subject: <jsp:forward> with params