Issue
I made a project on Netbeans on my local machine with JDK 1.7 (32-bit)
On running the application (using tomcat 8.0 server on netbeans), it works perfectly on http://localhost:8080/WebApplication1
.
I copied the war file from the dist directly and transferred it to my Windows VM server with tomcat 8.0 and jdk 1.8 installed (64-bit). Then the war file was uploaded through tomcat's manager web app.
Note: 'localhost:8080/' and 'localhost:8080/manager' ran without any issue.
However, when I go and run the application (http://localhost:8080/WebApplication1
) - it throws the following errors.
org.apache.jasper.JasperException: Unable to compile class for JSP
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:579)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.IllegalArgumentException: Page directive: invalid value for import
org.apache.jasper.compiler.Node$PageDirective.validateImport(Node.java:610)
org.apache.jasper.compiler.Node$PageDirective.addImport(Node.java:593)
org.apache.jasper.compiler.Parser.parsePageDirective(Parser.java:344)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:458)
org.apache.jasper.compiler.Parser.parseFileDirectives(Parser.java:1782)
org.apache.jasper.compiler.Parser.parse(Parser.java:136)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:227)
org.apache.jasper.compiler.ParserController.parseDirectives(ParserController.java:117)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:194)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
The <%page import %>
I have in my JSPs are 'java.util.*' and 2 java classes which are part of my project. Rest my java classes import some 'java.' packages
Additional info:
- I have set 'Path' environment variable to 'C:\Program Files\Java\jdk 1.8\bin'
- I have tried including 'org.apache.jasper.jar' to my project (& war) too
- jdbc4.jar is also imported in library
What seems to be the problem? I am unable to make out the source of the problem. Is it because of 32-bit vs 64-bit? or jdk 1.7 vs 1.8? or missing environment variable? or problem in tomcat configuration? something else?
Solution
Problem was in my import statement, which included:
Original code
<%@page contentType="text/html" pageEncoding="UTF-8" language="java" import="java.util.*,mypackage.one.*,mypackage.two.*;"%>
The issue was the ;
at the end of the import statement!
Corrected code:
<%@page contentType="text/html" pageEncoding="UTF-8" language="java" import="java.util.*,mypackage.one.*,mypackage.two.*"%>
Answered By - Playmaker
Answer Checked By - David Goodson (JavaFixing Volunteer)