title: Could not compare string value in jsp scriptlet
body: <pre><code>Code is something like 
  
      2: &lt;%
      3: String rolename = (String)session.getAttribute("roles");
      4: out.println("role is " + rolename);
      5: if(rolename.equals("MY_ROLE")){
      6: out.println("tension");
      7: }
      8: %&gt;
  </code></pre>
  
  <p>Problem is: line 4 is printing value of rolename correctly i.e "MY_ROLE", but I am getting null pointer exception on line no 5, which I am assuming because of rolename is null. </p>
  
  <pre><code>Error is as below : 
  </code></pre>
  
  <p>org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/views/fragments/menu.jspf at line 10</p>
  
  <pre><code>    7: &lt;%
      8:    String rolename = (String)session.getAttribute("roles");
      9:    out.println("role is " + rolename);
      10:   if(rolename.equals("MY_ROLE")){
      11:       out.println("tension");
      12:   }
      13:%&gt;
  
  Stacktrace:
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:521)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:229)
      org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
      org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  
  
  root cause 
  
  java.lang.NullPointerException
      org.apache.jsp.WEB_002dINF.views.pages.view_jsp._jspService(view_jsp.java:106)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:229)
      org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
      org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  
  Please help.
  </code></pre>