 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Servlets 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
|
|
|
|

November 6th, 2004, 01:16 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
installing a servlet
I have completed servlets 101, i.e. I have downloaded Jakarta, installed Tomcat, and gotten my servlet working.
I thought that servlets 102, i.e. installing the servlet on my server, would be easy, but I find that I don't know how to do it.
1. What do I upload, the jar file?
2. There is a cgi directory. Do I put it there, or in what directory?
3. How does the server know to run a java program?
Page 16 of Wrox's Apache Tomcat says to access a servlet via
www.servlet.com/servlet/ServletName
so I set up a directory named "servlet" and uploaded my jar file to it, but that does not work.
Can someone set me straight on this?
|
|

November 7th, 2004, 03:12 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello,
Not sure what your problem is, I remember you got your servlet working ok from the Apache Tomcat forum.
If I am right, you got it working on a local machine, and now want to run it on a server?
If so you need to set the server up in the same way, and use the same directories as you did on your local machine. You can use alternative directories, but these need to be defined in the relevant .xml files.
Perhaps you could expand on your problem.
|
|

November 8th, 2004, 02:17 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
So I have to add all those jakarta directories, meaning the following:
A webapps directory in the root,
myApps inside webapps,
WEB-INF inside myApps,
classes and web.xml inside myApps,
and the servlet jar or class file inside classes.
Somehow the server knows from that directory structure to run the servlet when I use the URL http://www.MyServer/servlet/myServlet
I'll give it a try.
|
|

November 9th, 2004, 08:08 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yup, you will need to create your webapps, change xml files, everything you did on your local machine.
As for:
"Somehow the server knows from that directory structure to run the servlet when I use the URL www.servlet.com/servlet/ServletName"
The server will look for whatever you specified it to look for, /servlet/ is the default, which i belive can be changed.
|
|

November 9th, 2004, 08:45 AM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I realize that the server will go to whatever URL I have given, using the directory structure that I have set up. The part that I wonder about is its being able run a Java program. What gives it that ablility?
It knows enough, when it gets to a cgi directory, to run a pl, C, or C++ (but not Java) program. I guess the "/servlet/" in the URL tells it to use the servlet directory structure, use the web.xml file, etc., AND to run java.
|
|

November 10th, 2004, 05:48 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
This is what I tried, Angry cat:
I uploaded the servlet-examples directory to my server (dnadraw.com).
Then, since http://localhost:8080/servlet-exampl...loWorldExample had worked in Tomcat, I used http://dnadraw.com/servlet-examples/...loWorldExample, and got this
404 Not Found
error message.
The requested URL /servlets-examples/servlet/HelloWorldExample was not found on this server.
There's something I'm missing in all this.
|
|

November 11th, 2004, 05:52 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Regarding your question as to how the server 'knows' how to run java:
Tomcat is written specifically for java, and thus requires Java to be installed on your machine. One problem I ran into when I first uploaded files to a server was that an older version of java was running, which I had to upgrade before it wuold run my programs.
Apache can hand off processing of jsp to Tomcat, presumably by looking at the suffix of the page, i.e. .jsp
I am not sure how this would work with servlets though. If you were calling from a jsp page, you would already be using Tomcat so to speak, but if you called from a html form I am not sure.
Its not an issue I have had to face as I am running Tomcat in stand alone mode, are you using Apache as well? If so do you have the jk2 connector installed?
|
|

November 11th, 2004, 12:37 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
There's so much I don't understand.
E.g. "using Tomcat in stand-alone mode". What does that mean, and what is NON stand-alone mode?
And if I run Tomcat on my web server (do I?), then I need to upload Tomcat and Java to my server, then set the CLASSPATH and JAVA_HOME, etc. (I only know how to do that on my own machine).
Will have to keep reading.
|
|

November 11th, 2004, 04:24 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yes you need to upload Tomcat and Java to your server and set it up as you did on your local machine. You can use the same configuration as you did on the local machine, its exactly the same, even if you go from Windows to Linux, though you will obviously need to get the correct version for your OS if it is different.
Tomcat can be run standalone to serve both HTML and JSP, however it is better to plug it into Apache. Apache is more stable and secure, also it is faster at serving HTML. You have to get an Apache module to do this, Im pretty sure its called JK2 connector. You then have to set up Apache to send JSP requests to Tomcat.
As I said Im currently running Tomcat standalone as I have not been able to compile the connector. I simply shut Apache down and started Tomcat instead.
Also check you have an up to date version of Java on your server, or you may find your code will not run. You will need to reset the classpaths if you do this.
Hope this helps.
|
|

November 11th, 2004, 08:13 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Forgot to ask, do you have root access to the server, you will need it to install tomcat.
|
|
 |