RAVITEJA SATYAVADA
RAVITEJA SATYAVADA

Reputation: 2571

Unable to compile class for 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.

Upvotes: 15

Views: 161475

Answers (8)

Vaibhav Adesara
Vaibhav Adesara

Reputation: 1

This ERROR occurs because you are importing something which is not class.

this ERROR mostly occurs in <%@page import=" "%> in JSP Page Directive.

because it controls the processing of entire JSP pages. It gives direction to the server regarding the processing of page.

in below code try to import packages in "*" form so it will not give you this type of ERRORS. like <%@ import="java.io.*" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"  import="java.io.*"   %>

<%@ page import = "java.io.*" %> you will find error in this line . this code can help you to solve your error. by putting " * " in your importing package code..

I think this will help you. Thanks

Upvotes: 0

Filipe Figueira
Filipe Figueira

Reputation: 1

In my case, I was using the 6.0.24 Tomcat version (with JDK 1.8) and resolved the problem by upgrading to the 6.0.37 version.

Also, if you install the new tomcat version in a different folder, do not forget to copy your previous version /conf folder to the new installation folder.

Upvotes: 0

Vinay Sharma
Vinay Sharma

Reputation: 41

Either you can Downgrade to JRE 1.7.49

or if you want to run on JRE 8

Step to fix:-

  • Go to Lib folder of Liferay Tomcat .

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

  • Restart the Server

Upvotes: 3

Abhimanyu
Abhimanyu

Reputation: 1

Try adding this to your web.xml:

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

Upvotes: 0

patel jigar
patel jigar

Reputation: 52

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

enter image

Upvotes: 0

Cleber Jorge Amaral
Cleber Jorge Amaral

Reputation: 1452

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/

Upvotes: 9

Vijay Gajera
Vijay Gajera

Reputation: 1364

I faced same exception in eclipse neon version exception is like 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 using Apache tomcat 8 of maven plugin and i tried to update that but face same issue.

After i download new external apache tomcat version 8.5.14 and run project using this its will success for me

I hope some one to useful this for resolve above exception

Upvotes: 1

Jan Zyka
Jan Zyka

Reputation: 17898

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.

Upvotes: 12

Related Questions