 |
| Apache Tomcat General discussion of the Apache Tomcat servlet container. For discussions specific to the Professional Apache Tomcat book, please see the book discussion forum for that book. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Apache Tomcat section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

September 15th, 2004, 05:46 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Dear angry cat,
Am still not able to run a servlet. Here is exactly what I did:
1) setenv JAVA_HOME /usr (that's where Java is on the Mac)
2) ~/Desktop/jakarta-tomcat-5.0.27/bin/shutdown.sh
3) setenv CATALINA_HOME ~/Desktop/jakarta-tomcat-5.0.27 (jakarta is on the desktop)
4) setenv CLASSPATH /Users/marvin/Desktop/jakarta-tomcat-5.0.27/webapps/ROOT/WEB-INF/classes
5) ~/Desktop/jakarta-tomcat-5.0.27/bin/startup.sh (started up Tomcat)
6) compiled HelloServlet (successfully) and put HelloServlet.class in the above classes directory
Then http://localhost/servlet/HelloServlet gave me the File Not Found (404) error.
web.xml and server.xml have not been changed.
Where did I go wrong?
Thanks again for the help.
ms
|
|

September 15th, 2004, 06:34 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello,
I would agree that the error seems to be with the path, although once again Id like to know whether you have the test examples that come with tomcat working. This would prove whether it is an error with your path/servlet or whether there is a more fundamental problem.
To configure tomcat I set the path in the startup.bat and shutdown.bat files (on windows). In linux there was a single seperate file for setting the classpath. You need to set this path in the startup and shutdown files so tomcat knows where to find the jvm. I think you have done this else I doubt you would have got this far.
I then edited the web.xml file as I explained before. Be sure to edit the one in the path I gave as there are others.
Also be sure you un commented the correct parts, there are others similar to the second snippet I gave.
I then started tomcat and was able to run the test jsp and servlets, and was therefore sure it was configured ok.
When I came to write servlets, I used a seperate compiler as you seem to be doing and dumped the class in the same folder you did, I used the same /servlet/ in the url and it worked ok.
I can only suggest you check the web.xml, shutdown and restart the server and see if you can find the bug, but first try the sample files provided with tomcat to be sure your servers working properly!
If youre still stuck you could try the Sun Java forums in addition to this one, though they are not tomcat specific.
Ill have another look at my own setup and get back to you if I find anything else.
Dont worry too much, youll get there in the end and I have to say its well worth it!
|
|

September 15th, 2004, 06:45 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Just checked some notes I made when setting up, nothing new, just the 3 steps I mentioned:
Amend startup and shutdown files
Edit web xml
Add servlets to c:\tomcat\webapps\root\web-inf\classes
Thats all I did to get it working.
|
|

September 16th, 2004, 03:43 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
|
|
<<tomcat Ins.>>\web-inf\classes
Should be added to you classpath
|
|

September 16th, 2004, 03:48 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
|
|
can u cut & paste your code, what is the package statemnt ...
simply copy & paste of .class files will give package def. problem
you can do onething, put .java also and compile once
javac HelloServlet2.java
Are you using IDE then, Let deployment do that for you....
Gokul
Quote:
quote:Originally posted by mbs31
To gokul bir:
I tried unsuccessfully to run a servlet in a package, as you suggested. This is what I did:
1) created a directory, coreservlets, in jakarta-tomcat-5.0.27/webapps/ROOT/WEB-INF/classes
2) put HelloServlet2.class in that directory
3) set CLASSPATH to that directory
4) gave the browser the URL: http://localhost/servlet/coreservlets/HelloServlet2
(BTW, I have set the port to 80 in servlet.xml)
The browser tells me URL NOT FOUND.
I can run html files, I can compile java servlets, but I am unable to run them.
I'm somehow using the directories wrong.
ms
|
|
|

September 16th, 2004, 04:50 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
To glokul_bir,
Why are you telling this user to put servlets in packages?
Servlets do not need to be put into packages to work.
The only way packages could cause an error in this instance would be if one was specified when it did not need to be.
All this user is trying to do is run a helloWorldServlet, the only classpath that needs to be set is that for java, everything else should be standard, they are not trying to alter the location for servlets, just get the first one to run.
|
|

September 16th, 2004, 09:38 AM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
To angry cat:
I started out using the examples from the Core Servlets and JavaServer Pages book, by Marty Hall. Here's what DOES work for me:
1) http://localhost/Hello.html - a simple html file that displays Hello
2) http://localhost/Hello.jsp - a simple jsp file that displays Hello and the date. The date, via Time: <%= new java.util.Date() %> DOES NOT display.
3) javac -cp Hello.java DOES compile into Hello.class, so my CLASSPATH to the servlet jar files is correct.
As I told you, running Hello.class does NOT work, either through using /servlet/ or modifying web.xml and using my own directory.
Please tell me how you set the path (CLASSPATH?) in startup.sh and shutdown.sh. I think I set it in a shell startup file with unix, but I haven't done that.
The only thing I changed in web.xml is uncommenting
And I changed the port to 80 in server.xml.
ms
|
|

September 16th, 2004, 11:28 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello again,
Forget the tests in your book, there are sample servlets and jsp examples bundled with tomcat. You can be sure there are no errors in these.
As I said before look in the left hand margin of the tomcat home page for the links. If these dont work then tomcat is not set up properly.
As for the startup and shutdown files, in windows I followed these instructions:
Edit the files c:\Tomcat5\bin\startup.bat and c:\Tomcat5\bin\shutdown.bat and insert the following line after the first line:
set JAVA_HOME=c:\j2sdk1.4.0_01
Obviously the files will be different on a Mac, as will your paths.
Setting the java classpath for your machine DOES NOT negate the need to do this. You MUST edit these files (or file as I found on Linux).
Make sure you try the examples INCLUDED WITH TOMCAT. Just a couple of clicks and youll know for sure whether your installed properly.
|
|

September 16th, 2004, 11:37 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello again,
Missed some points in your mail.
1) Hello.html is html NOT jsp so it will display, it is not dependant on tomcat.
2) If neither jsp or servlets will display then it looks like you are not configured, i.e. it is not your servlet path that is wrong.
3) The fact your compiler builds the servlet is not really relevant to tomcat. If there was an error in the servlet after compilateion tomcat would give you an error message relating to the servlet, so at least you would know tomcat could see it/the path was ok.
On the other points you mention, changing to port 80 is what I do, no problem there.
Un commenting should add functionality, I cannot see that causing an error.
If you havent edited the startup file, you MUST do this BEFORE anything else. Obviously restart tomcat after your changes are made.
|
|
 |