File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Program to set use a session, please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
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: 396
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: 61103
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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
 
Don't get me started about those stupid light bulbs.
 
subject: Program to set use a session, please