| | |
jsp sessions and scriptlet
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Hey, I'm getting so fustrated with this now!! I'm making a site in jsp and I have created the registration page and the login page and everything works fine. However I want to start to use the session login to personalise the page depending if they have logged in or not. I thought I had done this using the following code as it worked fine once you had logged in but if you went to the page without logging in it throws a internal server error print stack trace error 500 with a NullPointerException.
I'm guessing its because the session is empty but I tried with an if statement to test if it is null and this didn't work either.
Any help would be awesome as I'm going mad trying to fix this!
Cheers
Doops
JSP Syntax (Toggle Plain Text)
<% if (sess.getAttribute("loggedUser").toString() == null) { %> <jsp:include page="\LoggedSessionMenu.jsp" /> <% } else { %> <jsp:include page="NonSessionMenu.jsp" /> <% } %>
I'm guessing its because the session is empty but I tried with an if statement to test if it is null and this didn't work either.
Any help would be awesome as I'm going mad trying to fix this!
Cheers
Doops
The string you get back from the session is null, so your attempt to call toString() on it results in an NPE.
You should really use JSTL as well.
Something like
Makes it immediately apparent what you're trying to do, and will not result in an NPE.
You should really use JSTL as well.
Something like
JSP Syntax (Toggle Plain Text)
<c:choose> <c:when test="not empty session.loggedUser"> ... </c:when> <c:otherwise> ... </c:otherwise> </c:choose>
Makes it immediately apparent what you're trying to do, and will not result in an NPE.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
![]() |
Similar Threads
- JSP Sessions Help (JSP)
Other Threads in the JSP Forum
- Previous Thread: how use iframes in a form
- Next Thread: Connecting JSP to Oracle, problems with table
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial update video web






