aspose file tools*
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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "can     logic:forward  pass a parameter?" Watch "can     logic:forward  pass a parameter?" New topic
Author

can logic:forward pass a parameter?

Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 274
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.

Kim
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.

http://localhost/myApp;jsessionid=570EC5422F3E742FA15AE48BD4A59754?queryString=true

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: 274
Thanks very much Nathan. I tried to change my URL to

http://localhost/myapp;jsessionid=1234?name=Kim

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: 274
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:

http://localhost/myApp/init.do?name=Kim

when I get to the init.do 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
Kim,

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 ]

Merrill
Consultant, Sima Solutions
Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 274
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="/init.do">
<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 \init.do 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
Kim,

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: http://aspose.com/file-tools
 
subject: can logic:forward pass a parameter?