This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Struts and the fly likes can     logic:forward  pass a parameter? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "can     logic:forward  pass a parameter?" Watch "can     logic:forward  pass a parameter?" New topic

can logic:forward pass a parameter?

Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 276
Hi All,
Thanks so much for your help over the last few days. Don't know what I would do without Javaranch!
I have an app which will start up with a URL that looks like :

In my web.xml, I have

In index.jsp I have

In struts-config I have

in my InitAction class I have

My problem is that in the InitAction, the value of sessionID I get is null, even though on the URL I can see that there is a value appended there.

I think I must be missing something. Is there a way that I can bypass the trek through index.jsp and go right to the InitAction ? If not, am I missing something in my attempt to pass the PFSessionID parameter through to the action?

Thanks very much for any answers.

Nathan Hook
Ranch Hand

Joined: Jan 10, 2005
Posts: 81
Typically a session id isn't located in the url query string.

For example tomcat uses a ; instead of a ? for passing the jsessionid.


The session id is after the uri (myApp), but before the query string (?).

Hope that helps.
Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 276
Thanks very much Nathan. I tried to change my URL to


and then in the action tried a request.getParameter("jsessionid");
and request.getParameter("name");

both of these returned null.

The reason I am doing this is I want to compare the sessionID passed on the URL to the actual sessionID which I successfully do get usingrequest.getSession().getId(). I want to use the name parameter for another reason. I can't seem to get at either parameter though!
Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 276
Well, am about to give up on this one. Found out that if I make my url include the action name (and remove the part of web.xml that directs user to index.jsp) I can pull the items off the URL fine. I seem to hit the problem when I go through the jsp page. I wanted to do it that way so I didnt have to have the action on the url since it looks a bit clunky, but cant seem to find a way around this and still be able to pull the params off of the url.

So, here is what I end up with for a URL:


when I get to the action, I pull the parameter
"name" off of the request fine.

Anyone know of a way to do this when going through index.jsp?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864

You can pass a parameter from your index.jsp. You just can't do it using the <logic:forward> tag.

Try it this way:

Note: The above will only work on web appliation that uses Servlet version 2.4 or above. Otherwise, you have to use a scriptlet for the value attribute.
[ February 05, 2007: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 276
Hi Merrill,
Thanks again for your help. This one is a real stymie, no matter what I try it doesnt want to work. I tried both of these scenario's and still keep getting null:

<jsp:forward page="/">
<jsp aram name="PFSessionID" value="<%request.getParameter"PFSessionID")%>" /></jsp:forward>

and also the way you had specified in your post. When I do this in the action:

String sessionID = request.getParameter("PFSessionID");

I continue to get a null result for sessionID. I am glad I can get this to work by adding the \ to the url, but it is driving me nuts because I know I SHOULD be able to make this work the way you describe.

One more question I thought of in trying to figure this out is, when I am in the jsp page in the scriptlet, how does the jsp know that the reference to "request" means the HTTPServletRequest? Maybe I am supposed to specify that in a header or in the struts-config? Though this problem has been frustrating I am learning a ton in the process !
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864

I don't know if you were just being careless in your post, but the code you posted is incorrect. It should read:

In answer to your question, the JSP specification dictates that there are certain "pre-defined" variables in any JSP. "request" is one of them, as is "session", "response", etc. This link contains a complete list.

A "pre-defined" variable means you don't have to declare it or instantiate it. The container does it for you.
[ February 06, 2007: Message edited by: Merrill Higginson ]
I agree. Here's the link:
subject: can logic:forward pass a parameter?
It's not a secret anymore!