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 ?
. 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.
"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. "
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.