This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Servlets and the fly likes Program to set use a session, please Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Program to set use a session, please" Watch "Program to set use a session, please" New topic
Author

Program to set use a session, please

Zaynab Ejaz
Greenhorn

Joined: Nov 14, 2008
Posts: 6
I've created a HttpSession in a servlet and initialised it with a parameter, how can I access dat parameter in a JSP page, should set a Page Attribute or sumthing if so wat
Thnx in advance ^_^
Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
Originally posted by Zaynab Ejaz:
I've created a HttpSession in a servlet and initialised it with a parameter, how can I access dat parameter in a JSP page, should set a Page Attribute or sumthing if so wat
Thnx in advance ^_^


Your question is not pretty clear. Are you talking about how can you use the value that you have set in session. If so, request.getSession().getParameter("name") can help you in retrieving the value.
Mourouganandame Arunachalam
Ranch Hand

Joined: Oct 29, 2008
Posts: 395
As mentioned, if you have created a variable and stored in session scope, you can always access the variable until the session gets expired, doesn't matter if you are in servlet or jsp. You can try the same as suggested above. Pass the correct session variable name in the getParameter() method.

Mourougan


Mourougan
Open Source leads to Open Mind
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56192
    
  13

No, getParameter() is not correct. The method is named getAttribute().

And if you are following modern standards and using the EL rather than scriptlets on the JSP, you don't even need to bother with that.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Zaynab Ejaz
Greenhorn

Joined: Nov 14, 2008
Posts: 6
Yes I wanted to use the value I had set in the session
heres the code I wrote

String sname = String.valueOf(request.getSession().getAttribute("name"));

I had an outdated example that I couldn't use
thanks, you guys are a great help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Program to set use a session, please
 
Similar Threads
JBoss Seam
how to detect if javascript is enabled or disabled from Java Servlet
Is there a way to set a parameter from an action?
Servicing *all* requests
Passing parameters to actionMapping