Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Program to set use a session, please

 
Zaynab Ejaz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 398
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Zaynab Ejaz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic