• Post Reply Bookmark Topic Watch Topic
  • New Topic

can we use 'session' in a method of jsp?  RSS feed

 
yuvaraj KumarAmudhan
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


it is showing an error ------> 'session' cannot be resolved to a type!

i have to fetch some attributes from the session object in the jsp method.

suggestions please!

thanks

 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no you can't use session in methods other than service method because all the implicit objects have a local scope in the service method.
if you have got the need to do it then you are doing something wrong.rethink about it.
avi sinha
 
sujith Acharya
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
session is an implicit object in jsp. Its available only in scriplet. If you want to use it in a method, pass it as a method parameter.
 
yuvaraj KumarAmudhan
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks. but how can i fetch those attributes which are already put down in the session. i need to use those attributes in the method itself. but they are available only in the session. any idea?
 
Albareto McKenzie
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is still people programming methods in JSP? Is there any good reason to do so?

Use EL and do not use Java code in the JSP. You can access a session attribute just by putting it's name inside the ${} construcction. For example if in your Servlet or JspTag or whatever that is not a JSP you have set a session.setAttribute("myAttribute"); you can access it from your JSP just doing ${myAttribute}

Please, take a look to these links to understand better what is EL and how can the Java Standard Tag Library (JSTL) help:

http://java.sun.com/products/jsp/reference/techart/unifiedEL.html
http://java.sun.com/products/jsp/jstl/
 
yuvaraj KumarAmudhan
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks to all
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!