Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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

Scope in JSTL

Prashant Saraf
Ranch Hand

Joined: Sep 25, 2006
Posts: 56

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?
Stefan Evans

Joined: Jul 06, 2005
Posts: 1517
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: 56

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.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Scope in JSTL
It's not a secret anymore!