1

I am getting following error on my jsp. May be it's appearing due to session timeout but how to handle it:

org.apache.jasper.JasperException: An exception occurred processing JSP page /navbar.jsp at line 23

And my code is:

20:                         <li><a href="homepage.jsp"><i class="icon-home"></i> Dashboard</a></li>
21: 
22:                         <li><a href="MenuTeamMember.jsp"><i class="icon-group"></i> Team</a></li>
23:                         <%if (session.getAttribute("role").equals("National_Head") || session.getAttribute("role").equals("Admin")) {%>
24:                         <li class="dropdown">
25:                             <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-globe"></i> Distribution<b class="caret"></b></a>
26:                             <ul class="dropdown-menu">
user987339
  • 10,519
  • 8
  • 40
  • 45
error-404
  • 229
  • 4
  • 18

2 Answers2

0

Your session.getAttribute("role") may return null. Change your condition like below than see what is happend.

<%if ("National_Head".equals(session.getAttribute("role")) 
     ||       "Admin".equals(session.getAttribute("role")) {%>

In case of String equals first use fixed value (i.e "National_Head") which will never throw any NPE.

Masudul
  • 21,823
  • 5
  • 43
  • 58
0

Steps to come out of this:

1.Check for session.getAttribute("role") null or not

2)getAttribute returns Object,So you dhould cast it to String to check.

 <%if ((String)session.getAttribute("role").equals("National_Head") ||
                   (String)session.getAttribute("role").equals("Admin")) {%>

3)Immeadiatly read : How to avoid Java code in JSP files?

Community
  • 1
  • 1
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307