views:

47

answers:

1

I'm learning ANT and I'm trying to deploy a web application in tomcat 6.0.20 server. I build the test application and I deploy it with the manager ant tasks and everything goes right. I load a HTML page and it works... When I try to view a JSP tomcat give me a JasperException, coused by a NullPointerException in the auto-generated Servlet. The JSP is almost an HTML file with jsp extension. The Exception is throwed in the _jspInit method when it tries to run the following: _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory(); somebody can help me? thanks!

+2  A: 

Probably you have jsp-api-*.jar in /WEB-INF/lib. Remove it.

EDIT: Explanation

JSP API contains an abstract class JspFactory. It has a static field to store a server-specific JspFactory implementation. So, Tomcat sets a value of this field and JSP page initialization code reads it to obtain a JspFactory implementation. In your case you have two different JspFactory classes - one loaded by server classloader from server jars and another loaded by application classloader from /WEB-INF/lib. Because classes loaded by different classloaders are different classes, they have different static field values, therefore JspFactory obtained by the JSP code (_jspxFactory) is null.

This illustrates one of the possible problems caused by use of static fields.

axtavt
Indeed and he's not the only one: [click here](http://www.google.com/search?q=NullPointerException+_jspInit). Get rid of all server-specific libraries in `/WEB-INF/lib`. They don't belong there and would only collide with real server-managed libraries in `Tomcat/lib`.
BalusC
Thank you very mutch!That was the problem!! I put that jar there to test something and I forgot to remove it.Can you explain why it was an error? I know Tomcat has the jar in the lib dir, but why redundancy is bad?
s.susini
@user279481: Explanation added.
axtavt