 |
| 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 16th, 2004, 03:45 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
angry cat:
You are right! I am not configured properly. (I'm glad I told you about the date not being output.)
When I do startup, then http://localhost I get a Tomcat server page, but IT"S THE WRONG ONE! It does not have the menus at the left where you can choose examples to run.
When I open index.jsp in my webapps/ROOT directory and run it, the Tomcat page DOES have the menu at the left, so that's the correct one that I have to start up.
So starting the wrong Tomcat page is the cause of all my problems.
I'll go over the configuration part again.
Am starting to have some hope.
Another thank you.
ms
|
|

September 16th, 2004, 05:06 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Progress at last, like I said youll get there in the end.
I should point out it is not a case of opening the wrong page, localhost should point to this page by default if tomcat is configured properly.
Have you messed with any of the paths in the config files. if so return them to their original state.
To be honest if the config is messed up I would consider installing another copy in a different directory. This will re create the original config.
Also dont think the desktop is a good location, though this in itself shouldnt break it.
Follow the 3 steps I outlined earlier, get the examples working (on youre new installation). Once this is done copy files you need over from your existing version as necessary.
You really do need to take this stuff one step at a time, trying to sort more than one issue is a real headache.
Another suggestion is to make backups of server.xml and web.xml before each modification, its easy to make a mistake, then lose it, theres a lot of info in there.
Out of interest how are you compiling your servlets?
|
|

September 17th, 2004, 12:09 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
To angry cat:
I threw out 5.0.27, downloaded 5.0.28, and started from there, changing NOTHING in it.
I DID get the correct Tomcat startup page (with the menu), and all the jsp examples worked!
But then I compiled HelloServlet.java (which worked) and tried to run it (which didn't), and things quit working.
I trashed 5.0.28 and downloaded again, then did the following (just like I had done before when it worked) in unix:
1) setenv JAVA_HOME /usr
2) setenv CATALINA_HOME /Users/marvin/Desktop/jakarta-tomcat-5.0.28
3) ~/Desktop/jakarta-tomcat-5.0.28/bin/startup.sh
and it looked OK, but then
4) http://localhost:8080/
did not work, giving me the same 404 error message, which I get no matter what I do.
BTW, using http://localhost/ gives me a Tomcat window without the menus, which is what I had before and thought was working. Once I use that URL I am unable to get the correct one, http://localhost:8080/, to work. I get 404 errors.
Try that http://localhost/ (without changing the port to 80 in servlet.xml). What happens?
ms
|
|

September 17th, 2004, 12:23 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Update for angry cat:
It occurred to me that restarting the machine might get things to work, and IT DID (God knows why)!
Somehow I think that http://localhost/ messed up things, but who knows.
So I will continue on, trying to compile and run HelloServlet.java.
Will let you know what happens.
ms
|
|

September 18th, 2004, 08:54 AM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
To angry cat:
Still some stuff I don't really understand, but I'm up and running!
1) All the Tomcat examples work, and
2) I compiled my own program, put it in ServletExamples, added the proper lines to web.xml, and it works!
Next step: make my own directory and stop using the default URLS, i.e. /servlet/ in the URL.
My goal is to write a PDF file to the server.
Thanks again for your help.
ms
|
|

September 19th, 2004, 03:28 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello ms,
Glad you got it working.
Quite often you need to stop and start tomcat to get it to pick up changes to servlets, not sure why yet. You may not have had to shutdown the machine, just tomcat.
Whether you use localhost or localhost:8080 is simply down to which port you set tomcat to listen on. As port 80 is the default you do not need to enter it, hence localhost. For anything other than the default (80) you need to enter the port in the url hence localhost:8080.
localhost:8080 is therefore only correct if you have set tomcat to listen on this port.
Havent bothered trying to deploy in a different folder yet, so when you crack it let me know how its done!
|
|

September 20th, 2004, 06:32 AM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
To angry cat:
Re: deploying in a different folder
Here's how I did it.
First, notice that the URL for Tomcat 's HelloWorldExample servlet example is:
http://localhost:8080/servlets-examp...loWorldExample
So using using the default web.xml, and /servlet/ in the URL, tells Tomcat how to find HelloWorldExample.class. Tomcat (somehow) knows from this URL that it's in /webapps/servlets-examples/WEB-INF/classes.
To use your own directory (instead of servlet-examples), create it in /webapps, with the same structure as servlets-examples, i.e. with WEB-INF/classes subdirectories, and use /classes for your .java and .class files, as Tomcat does for its servlets-examples. The easiest way to do this is to duplicate the servlets-examples directory (with all its subdirectories), give it your own name, and put it in /webapps. I called mine myApps.
Then, putting your java program, say HelloServlet.java, into /myApps/Web-Inf/classes, you do the following:
1) compile it (you need jakarta-tomcat-5.0.28/common/lib/servlet-api.jar in your classpath)
2) add /myApps/Web-Inf/classes to your classpath. For me this is:
/Users/marvin/Desktop/jakarta-tomcat-5.0.28/webapps/myApps/WEB-INF/classes/
2) startup Tomcat again
3) http://localhost:8080/myApps/servlet/HelloServlet
--------------
Now, to use your own directory instead of the default one (i.e. no /servlet/ in the URL), you have to change your web.xml file. You put the following into /webapps/myApps/Web-INF/web.xml:
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/servlet1</url-pattern>
</servlet-mapping>
This allows you to use "servlet1" in your URL. You can throw away everything else that was in web.xml, i.e. inside <web-app> </web-app>.
Then use
http://localhost/myApps/servlet1
to run HelloServlet.
--------
I hope I got it all.
Let me know how it works for you.
Best,
ms
|
|

September 20th, 2004, 02:49 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the info, think I tried all that and couldnt get it working, but looking at what you did I was not entering the url properly in the browser, I hadnt used the sub directory for my app.
Will give it a go sometime, am not writing any more servlets at the moment so am not in a hurry.
One thing you have mentioned that I am curious about is the way you are writing/compiling your servlets. Are you using tomcat do do this somehow?
I myself use a seperate compiler.
|
|

September 22nd, 2004, 07:57 AM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
To angry cat:
I am using simple servlets that I downloaded, from Marty Hall's website for his Core Servlets and JavaServer Pages book.
I compile them using unix on my Mac.
ms
|
|

October 20th, 2004, 12:13 AM
|
|
Registered User
|
|
Join Date: Oct 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Copyright Marty Hall "Core Servlets" book:
Turning on the Invoker Servlet
The invoker servlet lets you run servlets without first making changes to the WEB-INF/web.xml file in your Web application. Instead, you just drop your servlet into WEB-INF/classes and use the URL http://host/servlet/ServletName (for the default Web application) or http://host/webAppPrefix/servlet/ServletName (for custom Web applications). The invoker servlet is extremely convenient when you are first learning and even when you are in the initial development phase of real projects. But, as discussed at length later in the book, you do not want it on at deployment time. Up until Apache Tomcat 4.1.12, the invoker was enabled by default. However, a security flaw was recently uncovered whereby the invoker servlet could be used to see the source code of servlets that were generated from JSP pages. Although this may not matter in most cases, it might reveal proprietary code to outsiders, so, as of Tomcat 4.1.12, the invoker was disabled by default. We suspect that the Jakarta project will fix the problem soon and reenable the invoker servlet in upcoming Tomcat releases. In the meantime, however, you almost certainly want to enable it when learning. Just be sure that you do so only on a desktop development machine that is not accessible to the outside world.
To enable the invoker servlet, uncomment the following servlet-mapping element in install_dir/conf/web.xml. Note that the filename is web.xml, not server.xml, and do not confuse this Tomcat-specific web.xml file with the standard one that goes in the WEB-INF directory of each Web application.
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
After Dark:
Your have to read carefully. This explains why you couldn't configure to run http://localhost:8080/servlet/HelloServlet
I admit the Tomcat 5 installs like a breeze on Windows, so you don't really care about any configurations. However, some configurations described in the book are particularly userful. In fact, I skipped those configurations and now I lost 2-3 hours of my time trying to figure out what was wrong. Glad I've figured out so quick :)
|
|
 |