Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 6th, 2004, 01:16 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?


Reply With Quote
  #2 (permalink)  
Old November 7th, 2004, 03:12 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #3 (permalink)  
Old November 8th, 2004, 02:17 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.


Reply With Quote
  #4 (permalink)  
Old November 9th, 2004, 08:08 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.


Reply With Quote
  #5 (permalink)  
Old November 9th, 2004, 08:45 AM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #6 (permalink)  
Old November 10th, 2004, 05:48 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #7 (permalink)  
Old November 11th, 2004, 05:52 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

Reply With Quote
  #8 (permalink)  
Old November 11th, 2004, 12:37 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #9 (permalink)  
Old November 11th, 2004, 04:24 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #10 (permalink)  
Old November 11th, 2004, 08:13 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Forgot to ask, do you have root access to the server, you will need it to install tomcat.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with servlet developer.ibm Servlets 1 September 12th, 2007 11:22 PM
Servlet Problem cziaul Servlets 2 April 28th, 2007 09:39 AM
servlet shiveka Servlets 1 October 9th, 2006 08:26 PM
Need help in servlet arunj82 Apache Tomcat 0 March 15th, 2006 07:16 AM
servlet directory? jgtez JSP Basics 2 March 7th, 2004 06:48 AM



All times are GMT -4. The time now is 08:28 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.