File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes How to invoke a servlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to invoke a servlet?" Watch "How to invoke a servlet?" New topic
Author

How to invoke a servlet?

Chris Mathews
Ranch Hand

Joined: Jan 08, 2001
Posts: 46
I need help in invoking a servlet.I have the executable but don't know how to invoke it through the local host? I may need step by step procedures for invoking the servlet.
Please help me.
Thanks.
Chris Mathews
Ranch Hand

Joined: Jan 08, 2001
Posts: 46
Anybody please reply.
I am using Tomcat 3.2.1 and JDK1.2.2 and trying to run the servlet on Windows 98. Please help.
I tried using http://8080/servlet/HelloWorld but it did not work.
How can I connect my executable to the local host.
I am going crazy.Help..
Asuthosh Borikar
Ranch Hand

Joined: Sep 29, 2000
Posts: 75
Did you try using a different URL?
http://localhost:8080/servlet/HelloWorld
Heath Lilley
Ranch Hand

Joined: Jan 09, 2001
Posts: 72
If you have set up the servlet correctly then the path "SHOULD" be:
http://localhost:8080/servlet/HelloWorld.
The localhost should be mapped to 127.0.0.1 in you hosts file on you "local machine". if the localhost doesnt work try:
http://127.0.0.1:8080/servlet/HelloWorld.
remember you need to specify the hostname : port# that the server is running on it should be the 8080 you already tried.

If that doesnt work read the following:
First make sure that your servlet is "registered"...I am not that familliar with Tomcat but i have worked with jrun/IIS and ibm webspere. There should be a file or gui where you tell the appserver where to find your servlet .class file. Next make sure you have a virtual directroy/web path set up so when the user enters the <hostname>/servlet/myservlet it knows to invoke that class file...
Hope this helps.
[This message has been edited by Heath Lilley (edited January 29, 2001).]
[This message has been edited by Heath Lilley (edited January 29, 2001).]
Chris Mathews
Ranch Hand

Joined: Jan 08, 2001
Posts: 46
Thanks for all your help but still I am not able to make it run.How do I register the servlet ? How do I let the servlet know where my class files are ? I think that 's the problem I am facing right now.Anybody who has worked with Tomcat please come forward and help me.
I am going nuts as I have already devoted more than 50 hours on this small problem and still with no success.
Thanks.
Chris Mathews
Ranch Hand

Joined: Jan 08, 2001
Posts: 46
I tried using Java Web Server also but I am getting the same problem.It simply says (in IE) that This page cannot be displayed.
Please let me know how to proceed from here.
Your help is highly appreciated.
[This message has been edited by Chris Mathews (edited January 30, 2001).]
Ajan Balakrishnan
Ranch Hand

Joined: Jan 04, 2001
Posts: 71
Keep your HelloWorld class file inside
c:\jakarta-tomcat-3.2.1\webapps\root\WEB-INF\classes directory
The above path is the default context.You can specify your own context by modifying the server.xml file. But just to begin with use the default context
Now restart Tomcat and try URL
http:\\localhost:8080\servlet\HelloWorld
I think this should solve your problem.
Ajan
Chris Mathews
Ranch Hand

Joined: Jan 08, 2001
Posts: 46
Thanks Ajan. I got it running on Sun's Java Web Server 2.0. But I think this is free only for 30 days that's why I want to run the servlets on something that's free. I think Tomcat is free and I am trying to use that as an option. What do you guys think? Despite the fact that my HelloWorld is finally running I want it to run on Tomcat. So far I am not able to make it run on Tomcat. This is where I need your help. There is no subdirectory under webapps so I can't see the root subdirectory and further subdirectories. I would like to know how do you start/restart Tomcat esp. after I have Java Web Server running.
Thanks.
Ajan Balakrishnan
Ranch Hand

Joined: Jan 04, 2001
Posts: 71
I think you have a wrong download. Use this URL
http://jakarta.apache.org/builds/jakarta-
tomcat/release/v3.2.1/bin/
and download jakarta-tomcat-3.2.1.zip file and unzip it. You should be able to find the directories under webapp.
I also forgot to mention some key points last time.
You have to set up 2 environment variables
1. JAVA_HOME point to your jdk directory, like c:\jdk1.2.2
2. TOMCAT_HOME point to you tomcat directory , in my case it is
c:\jakarta-tomcat-3.2.1
3. Add c:\jakarta-tomcat-3.2.1\lib\servlet.jar in your CLASSPATH
4. Add c:\jdk1.2.2\lib\tools.jar in your CLASSPATH
5. Add c:\jakarta-tomcat-3.2.1\bin in your PATH

I assume you know how to set up these variables. If not let me know ,i'll help you out on that
For starting and stopping tomcat , go to "bin" directory under the jakarta-tomcat-3.2.1 and double click startup.bat and shutdown.bat. Usually this should work if it doesnot try it from the DOS prompt
If you are looking for something free like tomcat the i would recommend you to get Resin(1.2.1 version). Use the follwoing URL for the download http://www.caucho.com/download/index.xtp .
Resin comes with a servlet engine and a standalone webserver. You can also integrate Resin with any other webservers like apache or IIS/PWS. I find it much faster than tomcat and easier setup.
FYI, if using resin keep all your servlet class files under
c:\resin-1.2.1\doc\WEB-INF\classes directory
Let me know if this helps.

Ajan
Chris Mathews
Ranch Hand

Joined: Jan 08, 2001
Posts: 46
Ajan,
I just downloaded Resin 1.2.1 and compiled the HelloApplet file. Now how do I run this servlet ? Please give me the detailed reply.If there is any link for the documentation please let me know.
Thanks.
Ajan Balakrishnan
Ranch Hand

Joined: Jan 04, 2001
Posts: 71
All documents are in .xtp format under Resin1.2.1\doc directory
You have to associate these documents with "Microsoft HTML Document 5.0" to view as a html document.
As i said in my previous reply all servlet class files should be inside resin1.2.1\doc\WEB-INF\classes ( default context) directory
Now for starting , from the DOS prompt execute the httpd.exe executable file which is inside resin1.2.1\bin directory. This will start the resin webserver. Also you can see an applet running with start and stop radio buttons with the . mark on start)
from the browser invoke your servlet http://localhost:8080/servlet/yourservlet
You are ready to go now.
Any problems let me know
No luck with Tomcat huh..
Ajan

[This message has been edited by Ajan Balakrishnan (edited January 31, 2001).]
Chris Mathews
Ranch Hand

Joined: Jan 08, 2001
Posts: 46
Ajan, thanks so much for reply.
Now I am encountering a new problem. As I mentioned I am running Java Web Server. It is still running and don't know how to stop it. So when I ran httpd.exe from resin1.2.1/bin I am getting an error which says "http can't bind to *.8080. Check for conflicting server" I don't know how to stop Java Web Server.I need your help here so that I can start resin server.
Please help.
Thanks.
narayan kulkarni
Greenhorn

Joined: Jan 31, 2001
Posts: 17
to Stop the httpd you can do two things
1 type in http://localhost:9090/ and wait till the Admin Applet downloads login using login name as admin and password as admin
When your given entry you get options to shutdown the javawebserver
2 I believe you are having Windows 98 so, if you press ctrl-alt-del you will get the list of processes running on your machine
Select the jserv and jre processes and click end task
Now you should not have any problem when you start Resin



Take up computer programming as fun and you will just enjoy it. Always keep in mind that in some way your program is going to make human life easier.
Ajan Balakrishnan
Ranch Hand

Joined: Jan 04, 2001
Posts: 71
Another way is change the http port number. Let's resin listen your port 80 instead of default 8080. This will let you run JWS and Resin at the same time. Remeber to turn off IIS/PWS from port 80 if at all it runs on that port . Follow the procedures as below
Open the file "resin.conf" (on wordpad editor) under directory
resin1.2.1\conf and change the line
<!-- the http port -->
<http port='8080'/>
TO
<!-- the http port -->
<http port='80'/>
Now stop and restart resin and try URL
http://localhost/servlet/YourservletName

Ajan


[This message has been edited by Ajan Balakrishnan (edited January 31, 2001).]
Chris Mathews
Ranch Hand

Joined: Jan 08, 2001
Posts: 46
Thanks Ajan. Thanks so much.
I am so happy today! Finally I was able to make it run on Resin.Thanks again.JWS is also running at the same time. Now I don't have to worry about the expiry date for JWS. Still no luck with Tomcat. But I am not very much worried at this time. Now I can move forward.
God bless you.
Enjoy the week-end.
Ajan Balakrishnan
Ranch Hand

Joined: Jan 04, 2001
Posts: 71
Good to know it's working
You too have good weekend
Ajan
Jan Volkmann
Greenhorn

Joined: Feb 01, 2001
Posts: 17
Originally posted by Ajan Balakrishnan:
Good to know it's working

Strange though that it wouldn't work with tomcat. I had the same problems with tomcat-3.2.1, jdk1.3, winNT. One has to be very careful with all those paths. Can't check them too often. If using jBuilder the URL is

By the way, there is no root folder beneath webapps. It works but can be quite frustrating.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to invoke a servlet?