Unable to compile class for JSP

I work in a JSP project. When starting a project using Netbeans with a Tomcat 6 server, I received the following exception:

org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 8 in the generated java file Only a type can be imported. com.TransportPortal.MyFunctions resolves to a package 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:349) org.apache.jasper.compiler.Compiler.compile(Compiler.java:327) org.apache.jasper.compiler.Compiler.compile(Compiler.java:314) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393) 

It has servelet-api.jar in the Apache Tomcat lib directory.

Please help me solve the problem.

+11
source share
7 answers

Due to the error, it seems that you are trying to import something that is not a class.

If your MyFunctions is a class, you need to import it as follows:

 <%@page import="com.TransportPortal.MyFunctions"%> 

If this is a package and you want to import everything into a package, you should do like this:

 <%@page import="com.TransportPortal.MyFunctions.* "%> 

Edit

There are two cases that will give you this error, edited for both.

+11
source

This may be due to the Java JRE version.

In my case, I need Tomcat 6.0.26, which introduced the same error with JRE 1.8.0_91. Switching to JRE 1.7.49 resolved it.

You can find more information at: http://www.howopensource.com/2015/07/unable-to-compile-class-for-jsp-the-type-java-util-mapentry-cannot-be-resolved/

+9
source

Or you can downgrade to JRE 1.7.49

or if you want to work on JRE 8

Step to fix: -

  • Go to the Lib folder in Liferay Tomcat.

  • Replace: - ecj-3.7.2.jar with ecj-4.4.2.

  • Reboot server

+3
source

I came across the same exception in the eclipse neon version exception as below

 org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 1 in the generated java file The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files 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:349) org.apache.jasper.compiler.Compiler.compile(Compiler.java:327) org.apache.jasper.compiler.Compiler.compile(Compiler.java:314) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 

I am using Apache tomcat 8 maven plugin and I tried to update it but am facing the same problem.

After downloading the new external version of apache tomcat 8.5.14 and starting the project using this success will be for me

I hope someone is helpful to resolve the above exception

+1
source

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

enter image

0
source

Try adding this to your web.xml:

 <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/your-servlet-name.xml </param-value> 

0
source
 <pluginManagement> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> </plugin> </plugins> 

-2
source

All Articles