0
votes

I'm experiencing and issue with tomcat where if I try to deploy my code I get the following error:

Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

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

Generated servlet error: Only a type can be imported. org.apache.log4j.Logger resolves to a package

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966) org.apache.jsp.secpay_jsp._jspService(secpay_jsp.java:78) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

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

Generated servlet error: Only a type can be imported. org.apache.log4j.Logger resolves to a package

org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328) org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414) org.apache.jasper.compiler.Compiler.compile(Compiler.java:297) org.apache.jasper.compiler.Compiler.compile(Compiler.java:276) org.apache.jasper.compiler.Compiler.compile(Compiler.java:264) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966) org.apache.jsp.secpay_jsp._jspService(secpay_jsp.java:78) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

I assume that there is an issue loading log4j somewhere, but I'm not sure where I need to load it. Where would I add a reference to add log4j to the deployment?

UPDATE:

Here is an example of code that breaks with at least a similar exception

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="org.apache.log4j.Logger"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
hello world

</body>
</html> 

if you konck out the reference to org.apache.log4j the page simply displays hello world...

2
Odd. Can you post an example JSP, preferably a short one?skaffman
Might be a classpath issue. Tomcat is not picking up the Log4J jar correctly, or it is missing. You might check the WEB-INF/lib directory of your webappakarnokd
I just tried that JSP in my appserver (JBoss 4.2 Tomcat) and it's fine. What are you running this in? What happens if you try import org.apache.log4j.* ?skaffman
It wasn't inthe WEB-INF that was the problem. I'm new to J2EE and didn't know thats where they needed to be put.Omar Kooheji

2 Answers

1
votes

You need to have the log4j-*.jar in either the WEB-INF/lib directory or in the tomcat/lib directory.

-1
votes

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

This Error occurs when the for the--> Service(ServletHttpRequest rq,ServletHttpResponse rs)throws Exp...on is not define inside the class..

So u need to do implement your code with First Service....(method), After it redirect (req,res) to doPost(...) then U will be get your solution..