Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scope in JSTL

 
Prashant Saraf
Ranch Hand
Posts: 57
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1720
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic