aspose file tools*
The moose likes JSP and the fly likes simple JSP and JavaBean, error 500 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "simple JSP and JavaBean, error 500" Watch "simple JSP and JavaBean, error 500" New topic
Author

simple JSP and JavaBean, error 500

northfield Sid
Ranch Hand

Joined: Aug 08, 2002
Posts: 106
I am working with a simple JSP program and bean.
The objective is to learn beans.
Here is the JSP file:
<HTML><HEAD><TITLE>Overriding toString() Method</TITLE></HEAD><BODY>
<%@ page import="OverridingToString"%>
<%! OverridingToString ots1 = new OverridingToString();
OverridingToString ots2 = new OverridingToString("New Message");
%>
<UL>
<LI>ots1 = <%=ots1%>
<LI>ots2 = <%=ots2%>
</UL>
</BODY></HEAD>
Here is the very simple bean:
public class OverridingToString{
String message = "Default Message";
public OverridingToString(){}
public OverridingToString(String msg){message = msg;}
public String toString(){ return message; }
}

Here is the error:
Error: 500
Location: /myJSPs/Hour8/overridingToString.jsp
Internal Servlet Error:
org.apache.jasper.JasperException: Unable to compile D:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\Hour8\overridingToString_1.java:6: Class OverridingToString not found in import.
import OverridingToString;
^
1 error
at org.apache.tomcat.facade.JasperLiaison.javac(JspInterceptor.java:898)
at org.apache.tomcat.facade.JasperLiaison.processJspFile(JspInterceptor.java:733)
at org.apache.tomcat.facade.JspInterceptor.requestMap(JspInterceptor.java:506)
at org.apache.tomcat.core.ContextManager.processRequest(ContextManager.java:968)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:875)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:484)
Note I am using the data structure D:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\HourXX
I am using the Sam learn in 24 hour book and presently on hour8.
Both files OverridingToString.java and overridingToString.jsp are in the folder Hour8
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
Hi Sid,
1. try to put your OveridingToString class in the tomcat\webapps\ROOT\classes directory.
2. I propose to create a own directory (with own web.xml) even for test-apps. This is very important for learning jsp. You seem to work in the root directory.
3. Your bean isn't very beany. Beany is with lots of getter and setter.
regards, correct me if I am wrong
Axel
[ August 28, 2002: Message edited by: Axel Janssen ]
northfield Sid
Ranch Hand

Joined: Aug 08, 2002
Posts: 106
>1. try to put your OveridingToString class in the tomcat\webapps\ROOT\classes directory.
I am not sure where to put it.
my tomcat is installed at:
d:\tomcat\jakarta-tomcat-3.3.1
so thus my bin folder is is at
d:\tomcat\jakarta-tomcat-3.3.1\bin
I have tried with your suggestion at:
d:\tomcat\webapps\ROOT\OverridingToString.java
and
d:\tomcat\webapps\OverridingToString.java
I still get the error:
Error: 500
Location: /myJSPs/Hour8/overridingToString.jsp
Internal Servlet Error:
org.apache.jasper.JasperException: Unable to compile D:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\Hour8\overridingToString_1.java:6: Class OverridingToString not found in import.
import OverridingToString;
Do I have to change any of my code?
>2. I propose to create a own directory (with own web.xml) even for test-apps. This is very important for learning jsp. You seem to work in the root directory.
Never worked with XML, so do not know how to do this?
>3. Your bean isn't very beany. Beany is with lots of getter and setter.
Yes indeed you are very right, but this is a very simple bean, latter I will work with more sophisticated beans.
northfield Sid
Ranch Hand

Joined: Aug 08, 2002
Posts: 106
> try to put your OveridingToString class in the tomcat\webapps\ROOT\classes directory
I have navigated to the folder D:\tomcat\jakarta-tomcat-3.3.1\webapps\ROOT\WEB-INF\classes
Prior to me placing any classes in the directory there were two files:
SnoopServlet.class
SnoopServlet.java
Is this normal?
I have put the class OverridingToString.java at D:\tomcat\jakarta-tomcat-3.3.1\webapps\ROOT\WEB-INF\classes
I still get the same error message:
Error: 500
Location: /myJSPs/Hour8/overridingToString.jsp
Internal Servlet Error:
What shall I do?
org.apache.jasper.JasperException: Unable to compile D:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\Hour8\overridingToString_1.java:6: Class OverridingToString not found in import.
import OverridingToString;
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
Sid,
hmm. O.k. give me one last try . Where did you put the jsp. It should be in jakarta-tomcat-3.3.1\Root\jsp\myJSPs\Hour8\overridingToString.jsp, I think.
Sorry it gets really dificult to trying to help you remotely. If you start with a new topic. Why not read a book. This one is quite good and available for free download: http://pdf.coreservlets.com/
There you get source code to start with and lots of chapters.
Axel
northfield Sid
Ranch Hand

Joined: Aug 08, 2002
Posts: 106
>Where did you put the jsp.
D:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\Hour8
previous "xxx.JSP" programs worked from this folder with no problem. These previous programs were all inclusive, so thus all java code and JSP code in one file. Now I have a simple java class file and a simple jsp file. This seems to be the problem.
>It should be in jakarta-tomcat-3.3.1\Root\jsp\myJSPs\Hour8\overridingToString.jsp,
From this directory I have 8 folders
jakarta-tomcat-3.3.1\
bin\
conf\
doc\
lib\
logs\
modules\
native\
webapps\
work\
So thus no root from "jakarta-tomcat-3.3.1" directory.
ROOT directory is in directory "Webapps"
but from here there is no directory callled jsp.
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
Sid:
create the file structure jsp\myJSPs\Hour8 under webapps\ROOT and put your jsp inside Hour8 dir.
northfield Sid
Ranch Hand

Joined: Aug 08, 2002
Posts: 106
> create the file structure jsp\myJSPs\Hour8 under webapps\ROOT and put your jsp inside Hour8 dir.

Created the directory structure.
New error.
tomcat can't even find the "JSP" file in this directory structure.
northfield Sid
Ranch Hand

Joined: Aug 08, 2002
Posts: 106
Below is a simple JSP file,
the file is located at D:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\Hour8

<HTML><HEAD><TITLE>Overriding toString() Method</TITLE></HEAD><BODY>
<%@ page import="Hour8.OverridingToString"%>
<%! OverridingToString ots1 = new OverridingToString();
OverridingToString ots2 = new OverridingToString("New Message");
%>
<UL>
<LI>ots1 = <%=ots1%>
<LI>ots2 = <%=ots2%>
</UL>
</BODY></HEAD>
Below is simple Java file.
The file has been complied so thus both the source file and .class file is located at
D:\tomcat\jakarta-tomcat-3.3.1\webapps\ROOT\WEB-INF\classes\Hour8
Here is the source code:
public class OverridingToString{
String message = "Default Message";
public OverridingToString(){}
public OverridingToString(String msg){message = msg;}
public String toString(){ return message; }
}
Please note previous all inclusive JSP programs worked, that is java code and JSP code were all in one file.
Now I have a simple JSP and a Java file, this does not work.
I have started tomcat and accessing the jsp file at browser address:
http://localhost:8080/myJSPs/Hour8/overridingToString.jsp
Error: 500
Location: /myJSPs/Hour8/overridingToString.jsp
Internal Servlet Error:
org.apache.jasper.JasperException: Unable to compile D:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\Hour8\overridingToString_1.java:6: Class Hour8.OverridingToString not found in import.
import Hour8.OverridingToString;
^
1 error
at org.apache.tomcat.facade.JasperLiaison.javac(JspInterceptor.java:898)
at org.apache.tomcat.facade.JasperLiaison.processJspFile(JspInterceptor.java:733)
at org.apache.tomcat.facade.JspInterceptor.requestMap(JspInterceptor.java:506)
at org.apache.tomcat.core.ContextManager.processRequest(ContextManager.java:968)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:875)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:484)
The book I am reading is Sams Teach YourSelf JSP in 24 Hours.
I haven't had any major problems so far with syntax and code for JSP. So therefore considered it to be a good book, a rating of say 7 out of 10.
The book does not explain anything on directories.
I would thus be greatful if any URL/book recommendation links of where to put "Java class" files can be read?
Thank you in adavance?
northfield Sid
Ranch Hand

Joined: Aug 08, 2002
Posts: 106
Please heed my new message requesting URLs/books I can read on JSP:
The book I am reading is Sams Teach YourSelf JSP in 24 Hours.I haven't had any major problems so far with syntax and code for JSP. So therefore considered it to be a good book, a rating of say 7 out of 10.
The book does not explain anything on directories.
I would thus be greatful if any URL/book recommendation links of where to put "Java class" files can be read? My webserver is Tomcat.
Thank you in adavance?
Amir Kamran
Ranch Hand

Joined: Apr 21, 2002
Posts: 48
Hello!
what i find out, what ur doing wrong is first of all in the java file dont define that it is in a package, the first line of ur java file must be
package Hour8;
Secondly, the web application u created in webapps is myJSPs where u store ur jsp file in the same web applicaion in WEB-INF/classes folder store ur package Hour8 which contain ur java file. i.e.
D:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\WEB-INF\classes\Hour8

I think this will solve ur problem.
northfield Sid
Ranch Hand

Joined: Aug 08, 2002
Posts: 106
> what i find out, what ur doing wrong is first of all in the java file dont define that it is in a package,
Please, please let me know where you have read this? The web has many articles on JSP, servlets and java, my book is good on teaching you how to program JSPs. it has nothing on where to put ".class" files.
>Secondly, the web application u created in webapps is myJSPs where u store ur jsp file in the same web applicaion in WEB-INF/classes folder store ur package Hour8 which contain ur java file. i.e.
D:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\WEB-INF\classes\Hour8
Sorry I do not understand at all what you want me to do?
>D:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\
From myJSPs directory there is no WEB-INF directory.
Amir Kamran
Ranch Hand

Joined: Apr 21, 2002
Posts: 48
Hello Again!
To study JSP what I think one should have some idea of Java and Servlet programming and also familiarity with the terms web Application, Web Server and Web Container etc. In every JSP and Servlet book there is some description on these topics.
Well I can give u little knowledge about these things:
A Web Application is a collection of Java Servlets, JSP pages other helper Classes, Static Resources such as HTML or XML documents, images etc.
A Web Container is basically a java runtime providing an implementation of the Java Servlet API, and other facilities for JSP pages. The web container is responsible for initializing, invoking and managing the life cycle of Java Servlets and JSPs.
Tomcat is a web container, which follows a particular directory structure for each web application. i.e. u have to store ur web application in the folder of webapps and in each web application there is a WEB-INF folder, which contains the classes folder. The Servlets and other java files are stored in the classes folder. While the JSPs can be store any where outside the WEB-INF folder. If u not follow this directory structure tomcat not recognize ur folder as a web application.
In the book �Java Servlets Developers Guide� there is a complete chapter on tomcat and webapps. Thanks to Javaranch I won this book from here.
Well, in ur program the folder myJSPs is actually ur web application, so u must have a folder of WEB-INF in it which contains the folder classes in which u store all ur java classes or packages. Store ur jsp file any where in the myJSPs folder but outside the WEB-INF folder.
I hope u understand all what I m talking about.
northfield Sid
Ranch Hand

Joined: Aug 08, 2002
Posts: 106
it doesn't work
northfield Sid
Ranch Hand

Joined: Aug 08, 2002
Posts: 106
My question is why does it seem to be so esotric in dividing JSP and class files seperately?
I am at the end my tether and really frustrated.
As I have tried with every known combinationss of folder combination. Of Webapps, ROOT, WEB-INF, classes etc ...

Here is all the information again:
My JSP File located at: D:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\jsp\Hour8
<HTML><HEAD><TITLE>Overriding toString() Method</TITLE></HEAD><BODY>
<%@ page import="OverridingToString"%>
<%! OverridingToString ots1 = new OverridingToString();
OverridingToString ots2 = new OverridingToString("New Message");
%>
<UL>
<LI>ots1 = <%=ots1%>
<LI>ots2 = <%=ots2%>
</UL>
</BODY></HEAD>
The class file is at D:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\WEB-INF\classes\Hour8:
package Hour8;
public class OverridingToString{
String message = "Default Message";
public OverridingToString(){}
public OverridingToString(String msg){message = msg;}
public String toString(){ return message; }
}
I start the simple web Application:
http://localhost:8080/myJSPs/jsp/Hour8/overridingToString.jsp
Error: 500
Location: /myJSPs/jsp/Hour8/overridingToString.jsp
Internal Servlet Error:
org.apache.jasper.JasperException: Unable to compile D:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\jsp\Hour8\overridingToString_1.java:6: Class OverridingToString not found in import.
import OverridingToString;
^
1 error
at org.apache.tomcat.facade.JasperLiaison.javac(JspInterceptor.java:898)
at org.apache.tomcat.facade.JasperLiaison.processJspFile(JspInterceptor.java:733)
at org.apache.tomcat.facade.JspInterceptor.requestMap(JspInterceptor.java:506)
at org.apache.tomcat.core.ContextManager.processRequest(ContextManager.java:968)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:875)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:484)

Please try to help?
Some one must be working on similar stuff with JSP???@???>???@?< <>
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
Sid.
I think you are close. Just change this line in your Jsp:
<%@ page import="OverridingToString"%>
TO
<%@ page import="Hour8.OverridingToString"%>
btw. by convention package names should be lowercase.
Axel
[ August 31, 2002: Message edited by: Axel Janssen ]
northfield Sid
Ranch Hand

Joined: Aug 08, 2002
Posts: 106
To Axel Janssen,
Many Thanx, for your patience.
Many people may look at this post and deem me credulous, and looking back at the post I would have to agree. I have the programming working now, many benedictions to you.
I think the problem stems from a culminating of programming problems that has been happening. This is not the Java/JSP side (apart from this) but a larger problem on distributed programming environment I am working on, which no matter how much I try, does not seem to work.
Sid.
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
Hi, here's another example. I hope it helps. Let's create a simple JavaBean that works with a JSP and a servlet. We will make:
1. a main.html that takes a String parameter and forwards it to
2. a mainController.jsp that instantiates a
JavaBean and populates it with the String parameter, then forwards it to a servlet
3. a JavaBean called InputBean that has a property called "input"
4. an OutputServlet that takes the property from InputBean and displays it on the browser.
For main.html we have:

Let's suppose the Tomcat4 install directory is called catalina. We'll put this html in the app root, C:\catalina\webapps\myContext.
For the JSP we have:

For more information on JSP tags, refer to the Sun link. Basically, since I will create the bean inside a package I will import it using the page directive, instantiate it with useBean, populate its "input" property with setProperty, and then finally forward it to the OutputServlet with servlet URL "/output". We'll also put this JSP in the app root, C:\catalina\webapps\myContext.
For the JavaBean, go to C:\catalina\webapps\myContext\WEB-INF\classes and create a folder named beans. Inside beans, create a JavaBean named InputBean:

Note that the public no-args constructor, as well the private fields and public accessor methods are part of the JavaBean specs.
Finally, we create the OutputServlet:

Note that we instantiate the actual JavaBean, retrieve its property and then display it to the client browser. Of course, this servlet resides in C:\catalina\webapps\myContext\WEB-INF\classes
We must register this servlet since the JSP uses a servlet mapping to forward the request. We must make the following changes to the web.xml file:

Note that all the <servlet> elements precede the <servlet-mapping> elements.
Finally, simply type the URL
http://localhost:8080/myContext/main.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: simple JSP and JavaBean, error 500
 
Similar Threads
How can I call a Servlet from a JSP page?
Error using taghandler, why does it not work?
Why does it not print out the database columns???
Need help with jsp page so that it calls a good working bean
jsp:include needs to have "flush=true"