GeeCON Prague 2014*
The moose likes JSP and the fly likes Scope in JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Scope in JSTL " Watch "Scope in JSTL " New topic
Author

Scope in JSTL

Prashant Saraf
Ranch Hand

Joined: Sep 25, 2006
Posts: 52

Hi,
I am using following
<c:set var="action" value="add" scope="request" property="action"/>

when i submit form is it possible to retrieve this variable call *action* in servlet, how can i use this data in servlet? is there any other way to do this?
thanks
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
Well, the <c:set> tag sets a request scope attribute.
In java code you would retrieve this via request.getAttribute("action");

However request scope attributes only last for one request.
Returning the JSP response marks the end of that.
Submitting the form will create a new request
So, no you won't be able to recover this value the way you have it now.

Suggestions - use a Session scoped variable - scope="session", and retrieve it with session.getAttribute()
- If you want a value to be passed to the next page as part of a form, create a <input type="hidden"> on the form with the required value. You can then retrieve the string value via request.getParameter("nameOfField") as usual
Prashant Saraf
Ranch Hand

Joined: Sep 25, 2006
Posts: 52

Hi, thanks.. as is there any other way to do this, because my servlet is handling request from multipal jsp's as security i do not want to use form hidden filed. if i use session it overlaps with other action if i click on cancel.
Thanks
 
GeeCON Prague 2014
 
subject: Scope in JSTL