Unable to Compile class for JSP. Tomcat 7.0.82

156
December 22, 2017, at 11:09 AM

I have created a war file from a java web project within eclipse. It very rightly created a classes and lib folders in WEB-INF directory containing compiled sources and referenced libraries. When I deployed this project on apache tomcat 7.0.82, it runs fine for most of the pages except Main2.jsp where I get the following exception

type Exception report

message Unable to compile class for JSP

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:675) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

The code of Main.jsp is below

<%@page import="assemble_xml.*"%>
<%@page import="java.io.*"%>
<%@page import="java.util.*"%> 
<%@page import="org.json.JSONObject"%>
<%@page import="org.json.*;"%>
<%
System.out.println("\n*** Inside Main2.jsp");
String data1 = request.getParameter("data");
String sourceApiId = request.getParameter("sourceApiId");
String bpFile = request.getParameter("bpFile");
String context = getServletContext().getRealPath("/");
//data1 = "{000:{name:mkyong.com,messages:[msg 1,msg 2,msg 3],age:100},001:{name:mkyong.com,messages:[msg 1,msg 2,msg 3],age:100}}";
JSONObject jsonObject = new JSONObject(data1);
System.out.println("\n*** Inside Main2.jsp: jsonObject"  + data1);
Operation op1 = new Operation ("");
HashMap<String, Operation> hm_xml_att  = op1.readOpAttribFromXML2(context+bpFile, jsonObject);
op1.writeXML(hm_xml_att,context + "auth_refine_output" + File.separatorChar + sourceApiId);
//BP bp = new BP(context,context + "\\auth_refine_output\\Mappings.txt",context + "\\auth_refine_output\\" + sourceApiId,context + "\\auth_refine_output\\OFBiz_Process.xml");
//response.setContentType("text/html"); 
//response.getWriter().write("Dataflow file (" +context + "\\auth_refine_output\\OFBiz_Process.xml) generated successfully");  
//System.out.println("\n*** Inside Main2.jsp: Dataflow file (" +context + "\\auth_refine_output\\OFBiz_Process.xml" + ") generated successfully");
%> 

I am pretty sure that the problem is due to the following two imports

<%@page import="org.json.JSONObject"%>
<%@page import="org.json.*;"%>

because, when I remove them, the error remains the same but now it's due to not resolving JsonObject to a type. Ironically, I have more than three files in WEB-INF\lib folder that seem like containing JsonOject. Those files are json-20090211.jar, json-20160810.jar and json-lib-2.4-jdk15.jar. All three files are also present in eclipse project but it runs flawlessly in eclipse. I am not the author of this project and not a java pro anyway. So, I wonder why do we have three files included as dep just for json? and why it works fine in eclipse but not from apache tomcat 7? Any pointers are highly appreciated.
regards

Answer 1

Semicolon in the last import was the problem. Changing the line from

<%@page import="org.json.*;"%>

to

<%@page import="org.json.*"%>

resolved the problem

READ ALSO
How to get detailed information on the computer&#39;s hardware (with Java)? [on hold]

How to get detailed information on the computer's hardware (with Java)? [on hold]

In Java, is it possible to get detailed information on a computer's hardware such as it's CPU, GPU, RAM space, sound and video cards? A standard library approach is preferred, but cross platform 3rd party libraries are ok

110
How can I make Static Property evalute when called

How can I make Static Property evalute when called

Does Java only call a declared variable once when declared inline in a class? How can I make it update whenever I call it?

95
Is iteration over LinkedHashSet faster than iteration over ArrayList

Is iteration over LinkedHashSet faster than iteration over ArrayList

I want to iterate over 2 collections each one roughly 600 recordsI want to compare each element of collection one with all other elements in collection two

90