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

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: [31] in the generated java file: [H:\eclipseWorkspace\J2EEspace\GlossaryPortal\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\Spring3HibernateApp\org\apache\jsp\WEB_002dINF\views\index_jsp.java]
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory

Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:476)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:264)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

The below line from the generated java file causing the issue from _jspInit() method

_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();

Previous to this exception, I was facing the below exception

java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config

To resolve this, I have downloaded the following JAR files from the web and placed it in /WEB_INF/lib folder

1) jsp-api-2.0.jar
2) jstl-1.2.jar

But you know, the jsp-api-2.0.jar is now lead to the exception “The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory”.

Solution

We should refer the target runtime in our project, not copy some libraries of an arbitrary servletcontainer make/version into our project. It would make our project incompatible with servletcontainers of a different make and/or version.

As simple, if you are using Tomcat 7 as server, then refer the jsp-api.jar from your Tomcat home directory’s lib folder. Don’t arbitrarily download some container version’s jsp=api file.

The project jar files should compatible with your servlet containers, which is the Tomcat Server that you are using as the Target Runtime.

So

You need to reference a server runtime in your project.

In Eclipse:

1) Choose “Project | Properties | Java Build Path | Libraries Tab”
2) Click “Add Library | Server Runtime | Apache Tomcat 7”
3) Click OK.
4) Clean your project, and build it again (“Project | Clean”, then “Project | Build All”)

That should do it!

Happy Learning 🙂

Advertisements

One Comment

  1. Jayesh
    Posted April 23, 2015 at 12:16 pm | Permalink | Reply

    Hi Sravan

    Good entry. Just to add , I was using a maven based project and kept gettting the same error

    What worked for me was removing the following two dependencies , they’ve been packaged with Tomcat 8 :

    javax.servlet
    javax.servlet-api
    3.1.0

    javax.servlet
    jsp-api
    2.0

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: