3

I have been working on a project for 6 months using net beans ide in order to develop an elearning web application.Everything worked fine inside net beans.(The project was from existing sources and i had to modify it,i didnt develop the entire application)I was using apache tomcat 7 in net beans.When i created the war file and deployed it nothing worked.I am getting null pointer exceptions in my session variables like i never give them a value.I am not able to understand what's the problem.Inside net beans i am using the same tomcat.

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

28:       Integer intObj = new Integer(project_id);
29:       httpsession.setAttribute("project_id",intObj);
30:       Hashtable projects=(Hashtable)session.getAttribute("projectsprofessor");
31:       if((Integer)session.getAttribute("professor")<=1 &&
32:           projects.get(project_id)==null)
33:                    {
34:           request.getSession().setAttribute("errorMessage","This project belongs to another professor!");


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:553)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:457)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause

java.lang.NullPointerException
    org.apache.jsp.System_jsp._jspService(System_jsp.java:149)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

This happens to the most of my pages.The strange is that some session variables are not null. I cannot understand where to focus!

thank you.

//Edit:Solved!The problem was that In the sources i got they have forgot *.class files in WEB-INF folder so when i clean-and-build in NetBeans the new classes didn't compile and net beans used the previous sources from the WEB-INF folder.When i deleted manually all the .class files from WEB-INF/Classes in the next clean-build used the new files

nikosdi
  • 2,138
  • 5
  • 26
  • 35

1 Answers1

7

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

Line 31 is thus the following:

if((Integer)session.getAttribute("professor")<=1 && ...

A NPE here can technically have only 2 causes:

  1. The session is null and getAttribute() will fail with NPE.
  2. The attribute "professor" returned null and the int autoboxing for <= will fail with NPE.

The first cause is unlikely as line 30 would otherwise have failed first. I'll bet that it's the 2nd cause. You need to check first if the attribute is not null.

Integer professor = session.getAttribute("professor");
if ((professor == null || professor <= 1) && ...

Perhaps you need to solve it at higher level, i.e. make sure that the "professor" attribtue is never null.


Unrelated to the concrete problem, Java code belongs in Java classes. It'll make debugging, testing and maintainance and such much easier.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • hm.... i am setting this attribute at the login servlet.It cant be null and if it is null the application cannot continue.Another symptom i just found out is tha the .properties files in the .war are the old ones and not the modified ones.Maybe this happens to the class files ?For example the previous login Servlet didn't store the professor information. – nikosdi Aug 23 '11 at 16:10
  • The exception is not lying nor been thrown just for decoration. It is definitely `null`. Likely your login servlet code is just bogus or your classpath is just dirty as your other symptoms indicate. Rebuild and cleanup everything. – BalusC Aug 23 '11 at 16:11
  • thank you!you are correct!Exception is not lying .....The problem is that net beans is compiling the previous files.I cannot understand why maybe i wiil create the war manually. – nikosdi Aug 23 '11 at 16:19
  • Eclipse offers "Build" and "Clean" options. Maybe you need to do same with Netbeans first. – BalusC Aug 23 '11 at 16:21
  • Ok i fixed it ! I really thank you! Maybe it was a bug of net beans. – nikosdi Aug 23 '11 at 16:31