• Post Reply Bookmark Topic Watch Topic
  • New Topic

unable to access implicit object session and EL sessionScope

 
Kumar Raja
Ranch Hand
Posts: 547
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello All,


I wrote a taglib for replacing certain part of strings based on some business rules and it is used as below in my jsp




Before the jsp is called, we set the attribute "username" into session which is verified. So, attribute not available in session is out of scope.

But in tag code, we observed that username is null (taken from sessionScope.username).

So I replaced EL with scriptlet using the implicit object session like which threw me a compilation exception upon accessing the page, saying that "session" could not be resolved.

But then I replaced with and this time it worked.

Ideally I want to use sessionScope and avoid scriptlets all together. But for some reasons, I could not get this work. Am I doing any mistake here ?

If I could get EL work for me, I would also like to use EL to form a string like .

Could some one help me understand why this is failing ?

 
Kumar Raja
Ranch Hand
Posts: 547
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok the reason I which I see for this failure is session="false" in my page directive. Sun says
"Whether the client must join an HTTP session in order to use the JSP page. If the value is true, the session object refers to the current or new session.

If the value is false, you cannot use the session object or a <jsp:useBean> element with scope=session in the JSP file. Either of these usages would cause a translation-time error. "
. So this is why my code is failing. This means, by setting session=false, we are telling the client does not need session to use the jsp. But why did it let me use request.getSession().getAttribute(). We are still using session here.
 
Paul Clapham
Sheriff
Posts: 21863
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the description that you posted more carefully:
If the value is false, you cannot use the session object or a <jsp:useBean> element with scope=session in the JSP file. Either of these usages would cause a translation-time error.

As you can see from your original post, when you tried to use the session object in such a case, you got no data. But when you tried a workaround which didn't use the session object (it used the request object instead) you were able to access data from the session.

You'll also notice (if you read carefully) that using session="false" in the page directive doesn't result in the non-existence of a session. It just says that you can access the page even if you don't have a session.
 
Kumar Raja
Ranch Hand
Posts: 547
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm,

Thank you Paul.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!