• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Getting Session variable in Action class to JSP

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchers,
In my Action class i have a string variable - myName. I have put this in session i.e. request.getSession(true).setAttribute("Name", myName);

Now i am Forwarded to "xyz.JSP". I want the variable in the previous Action class to be displayed in the JSP.

It can be done through "request.getParameter()". But on submission of xyz.jsp (i am using Validation.xml for validations) if the validation fails - "request.getParameter()" will return null when "xyz.jsp" is redisplayed.

So can someone suggest me, how to display the value in the jsp such that even if validation fails - when the jsp is redisplayed i can have that value.

Pls help....
[ July 26, 2006: Message edited by: Shailesh Pillai ]
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It can be done through "request.getParameter()".


Actually, no, it can't. Something passed as a parameter to the request is quite different than something set as an attribute to the HttpSession object. In java, you would retrieve this value with:

String name = (String)request.getSession().getAttribute("Name");

In a JSP, you can either use JSTL:

<c:out value="${Name}" />

or a Struts tag

<bean:write name="Name" />
[ July 26, 2006: Message edited by: Merrill Higginson ]
 
Shailesh Pillai
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Merill,
But i mentioned, request.getParameter() as a Second Alternative. Of Course, we cant retrieve any value set in session as request parameters.

But anyway got my answer i.e. through <bean:write .....>
 
I guess I've been abducted by space aliens. So unprofessional. They tried to probe me with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic