10

This is what I got on the browser screen when I try to run the JSP file.

The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory

Stacktrace:

org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330) org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439) org.apache.jasper.compiler.Compiler.compile(Compiler.java:334) org.apache.jasper.compiler.Compiler.compile(Compiler.java:312) org.apache.jasper.compiler.Compiler.compile(Compiler.java:299) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267) javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

And the jasper exception is thrown on the Tomcat window when I ran it.

4 Answers 4

35

The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory

That method was introduced in JSP 2.1. There are 3 causes for this problem:

  1. You're using an too old version of the JSP container (you need for example at least Tomcat 6.0).

  2. You've declared the wrong Servlet version in web.xml. JSP 2.1 goes hand in hand with Servlet 2.5, so your web.xml should at least be declared as per the Servlet 2.5 spec (you still need a Servlet 2.5 / JSP 2.1 capable servletcontainer for that).

  3. You've duplicated older versioned appserver-specific libraries into webapp's /WEB-INF/lib, like servlet-api.jar, jsp-api.jar and so on. You should never do that. It will only result in classloading collisions. Get rid of them in your webproject and leave/untouch them there in the appserver.

Sign up to request clarification or add additional context in comments.

7 Comments

ingcarlos,How did you resolve your issue? Which method did you use?
@janwen: just check any one of the listed causes.
Thanks BalusC,Cause1 and cause2 is ok.I delete servlet-api.jar and jsp-api.jar in my project.but still [code]An error occurred at line: 22 in the generated java file The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory[/code]
@janwen: then they're still wandering elsewhere in the classpath where they don't belong. For example, the /lib or /lib/ext folder of the JRE. Or you've other JARs containing an outdated JSP API, such as javaee.jar. After all, your /WEB-INF/lib should absolutely not contain any other libraries than the ones required by the webapp itself. See also this related question: stackoverflow.com/questions/4076601/…
No,I see the WEB-INF/lib folders of tomcat6,There is no that jars.
|
4
<dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>${servlet.version}</version> <scope>provided</scope> </dependency> 

also fixes the issues

Comments

1

The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory

This can also happen when your project requires a reference to a server runtime:

  • Right click on your project in Eclipse's "Project Explorer"
  • Choose "Build Path | Configure Build Path"
  • Click on the "Libraries" tab
  • Click "Add Library"
  • Select "Server Runtime" and click "Next"
  • Choose "Apache Tomcat 7", or whatever your server runtime version should be.

Note: This error can also happen for ANT builds, and for that case, you need to reference a target runtime in your ANT build.xml file... The following references a local tomcat installation, and uses its "lib" folders when doing the compile:

<project name="tomcat-demo" default="compile" basedir="."> <property name="tomcat-home" value="/path/to/your/tomcat/apache-tomcat-7" /> <path id="project-classpath"> <fileset dir="WebContent/WEB-INF/lib" includes="*.jar" /> <fileset dir="${tomcat-home}/bin" includes="*.jar" /> <fileset dir="${tomcat-home}/common/lib" includes="*.jar" /> <fileset dir="${tomcat-home}/server/lib" includes="*.jar" /> </path> ... </project> 

Snagged from this url:

Comments

1

For Maven, I also had to add the jsp-api dependency as a provided jar like this: (Some other dependency was pulling it in, I could never figure out which one, but this fixed it up)

<dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> <scope>provided</scope> </dependency> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.