Monday, August 4, 2014

How to debug JSP with help of compiled Java files in Eclipse

When I'm trying to access my jsp page, some of my code causing the problem and  it ran into some exception :P. But I know there is something wrong and want to resolve the issue and I'm not sure on how to debug a jsp file in eclipse while it is executing. I'm seeing the exception after the execution and only clue is this stacktrace. So this is the exception i'm facing.

HTTP ERROR 500 Problem accessing/index.jsp.


 Reason: Server Error Caused by: java.lang.NullPointerException at   
 org.apache.jsp.login_jsp._jspService(login_jsp.java:139) at   
 org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94) at   
 javax.servlet.http.HttpServlet.service(HttpServlet.java:848) at   
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) at   
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) at   
 javax.servlet.http.HttpServlet.service(HttpServlet.java:848)

From the stack trace it is clear that something is null in the code. It is at line no 139. 
C:\Users\sureshatta\AppData\Local\Temp\jetty-127.0.0.1-8888-war-_-any-\jsp\org\apache\jsp

That is not the line no in login.jsp  but the compiled file login_jsp.java.  As we all know, JSP converted to Java and then executes. The line numbers showing in the stacktrace are from that compiled java file. Cool , the question now is where is that compiled file stored to see the cause of error ?

Finally I found the place where the compiled jsp files. Here you can see the two files,

 login_jsp.class  
 login_jsp.java  
Do not touch that .class file and open the login_jsp.java file. From the stack-trace 

 org.apache.jsp.login_jsp._jspService(login_jsp.java:139)  

And the line no 139 in login_jsp.java is 

 parent= domain.startsWith("www.") ? domain.substring(3) : domain;

It clear that the only reason here to NullPointerException is domain.And I resolved that error. That's it. 

 How crap JSP is :-/.

Next >> Difference between final and effectively final in java 
Post a Comment