• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in running JSPs on Tomcat  RSS feed

 
Sanjeev Arora
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have version 4.0 of Tomcat and all my path settings are fine. I created a few JSPs and they were running fine until I decided to use a Java Bean in my JSP script. That's when I started getting servlet errors. My HTML file, source file and class file for the Java bean and the .jsp file are all in the same directory (\tomcat\webapps\examples\jsp). I'm working on a Win 2000 box. This is the error message I get:
A Servlet Exception Has Occurred
org.apache.jasper.JasperException: Unable to compile class for JSPC:\tomcat\bin\..\work\localhost\examples\jsp\sanjubean1_jsp.java:57: Class org.apache.jsp.UserData not found.
UserData user = null;
^
C:\tomcat\bin\..\work\localhost\examples\jsp\sanjubean1_jsp.java:60: Class org.apache.jsp.UserData not found.
user= (UserData)
^
C:\tomcat\bin\..\work\localhost\examples\jsp\sanjubean1_jsp.java:65: Class org.apache.jsp.UserData not found.
user = (UserData) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "UserData");
^
3 errors
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
Can someone please help me? I do not know what to do now.
Thank you,
Sanjeev
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"My HTML file, source file and class file
for the Java bean and the .jsp file are all in the same directory"
Thats not right - all class files need to be under the WEB-INF directory for the web application - either as loose class files under classes or in JARs under lib.
Remember, a JSP page gets turned into a servlet and that servlet has to obey all the rules for servlets, including class file locations.
Bill

------------------
author of:
 
Sanjeev Arora
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bill,
Thanks for your reponse. I put the class file in the right directory (\tomcat\webapps\examples\web-inf\jsp\classes) and I still keep getting the same error:
org.apache.jasper.JasperException: Unable to compile class for JSPC:\tomcat\bin\..\work\localhost\examples\jsp\sanjubean1_jsp.java:57: Class org.apache.jsp.UserData not found.
UserData user = null;
^
C:\tomcat\bin\..\work\localhost\examples\jsp\sanjubean1_jsp.java:60: Class org.apache.jsp.UserData not found.
user= (UserData)
^
C:\tomcat\bin\..\work\localhost\examples\jsp\sanjubean1_jsp.java:65: Class org.apache.jsp.UserData not found.
user = (UserData) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "UserData");
^
3 errors
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
Since my Java bean compiles successfully and I have the class file in the right directory, the problem seems to be something else. Why is Jasper complaining?
Thanks for any help that I get.
Sanjeev
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you importing the classes?
http://www.javaranch.com/ubb/Forum7/HTML/003739.html
 
Sanjeev Arora
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I tried that. This time I got this error:
org.apache.jasper.JasperException: Unable to compile class for JSPC:\tomcat\bin\..\work\localhost\examples\jsp\sanjubean1_jsp.java:3: Identifier expected.
import UserData.class;
^
C:\tomcat\bin\..\work\localhost\examples\jsp\sanjubean1_jsp.java:3: Identifier expected.
import UserData.class;
^
C:\tomcat\bin\..\work\localhost\examples\jsp\sanjubean1_jsp.java:11: Superclass org.apache.jsp.HttpJspBase of class org.apache.jsp.sanjubean1_jsp not found.
public class anubean1_jsp extends HttpJspBase {
^
3 errors
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
Obviously, the problem is not one of including the class file. There is something that Jasper cannot understand. Question is, what is it? Can someone please help me out with this error? I have tried a hundred different things but each time I get this Jasper message.
Thanks for the help,
Sanjeev
 
Cynthia Yao
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
UserData should under WEB-INF/classes (no addition hierachy) then the package if there is package,
and when you import it, you import as <%@ page import="(package)UserData"%> (no class)
 
Sanjeev Arora
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Cynthia and others. It works now! It is a great feeling to have stuff that was not working for the last 3 days work on a Friday afternoon.
Javaranch rocks!!
Sanjeev
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!