[Logo]
Forums Register Login
Program to set use a session, please
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 ^_^
 
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.
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
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.
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
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Dec 15, 2017 05:08:54.