Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to compile class for JSP

Tags:

jsp

I am working in a JSP project. While runnning the project using Netbeans with Tomcat 6 server, I got 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 Apache Tomcat's lib directory.

Please help me to resolve it.

like image 469
RAVITEJA SATYAVADA Avatar asked May 07 '11 08:05

RAVITEJA SATYAVADA


2 Answers

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

If your MyFunctions is a class, you should import it like this:

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

If it is a package and you want to import everything in the package you should do like this:

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

Edit:

There are two cases which will give you this error, edited to cover both.

like image 132
Jan Zyka Avatar answered Oct 20 '22 03:10

Jan Zyka


It may be related to Java JRE version.

In my case I need Tomcat 6.0.26 which presented same error with JRE 1.8.0_91. A downgrade to JRE 1.7.49 solved it.

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

like image 9
Cleber Jorge Amaral Avatar answered Oct 20 '22 05:10

Cleber Jorge Amaral