aspose file tools*
The moose likes Servlets and the fly likes unable to read session attribute in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "unable to read session attribute in JSP" Watch "unable to read session attribute in JSP" New topic
Author

unable to read session attribute in JSP

ragi singh
Ranch Hand

Joined: Mar 10, 2010
Posts: 198

hi i have a web application wherein i login using an html page and then i am redirected to a servlet MaintainingSessions and the code is as follows:-


and my JSP page is as follows:-


However when i run my application it gives me the error:-
Root cause of ServletException.
weblogic.servlet.jsp.CompilationException: Failed to compile JSP /Second.jsp
Second.jsp:19:3: Illegal token.
<%= session.getAttribute("Naming") %>
^
Second.jsp:19:3: Illegal token.
<%= session.getAttribute("Naming") %>
^

at weblogic.servlet.jsp.JavelinxJSPStub.compilePage(JavelinxJSPStub.java:328)
at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:237)
at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:182)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:235)
at weblogic.servlet.internal.ServletStubImpl.onAddToMapException(ServletStubImpl.java:408)
Truncated. see log file for complete stacktrace
>

Can anyone explain why i am unable to retrieve my session attribute from my session in JSP
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

The syntax for XML documents is a bit different. It should be


But you should definitely stay away from scriptlets and use EL instead (and name your attribute "naming" instead of "Naming" to avoid problems):


[My Blog]
All roads lead to JavaRanch
ragi singh
Ranch Hand

Joined: Mar 10, 2010
Posts: 198

i am not getting it any ways my jsp is unable to read scriptlet or any other jsp expression
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

It's because you are not using a common JSP file, but an JSP document. Look at your JSP : it starts with an xml tag, and then uses jsp:root. This is a JSP document notation. You won't be able to use the <% %> notation there. Check this.
ragi singh
Ranch Hand

Joined: Mar 10, 2010
Posts: 198

hi christophe ,

i am working in eclipse can you tell me how can i create my jsp so that my scriplets are all valid
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Did you read the tutorial I posted above ? If you insist on using the <% %> notation, get rid of the xml notation and use standard JSP instead.
 
jQuery in Action, 2nd edition
 
subject: unable to read session attribute in JSP