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 run servlet on Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to run servlet on Tomcat" Watch "How to run servlet on Tomcat" New topic
Author

How to run servlet on Tomcat

Grady Jamyson
Ranch Hand

Joined: Aug 04, 2002
Posts: 42
I use Tomcat as my servlet container, and I put servlet class in the WEB-INF/classes.
For example, I put Hello.class in webapps/ROOT/WEB-INF/classes/,
But I get 404 error when I try to load Hello servlet, I use http://localhost/servlet/Hello.
Any suggestion?
Thank you!!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12678
    
    5
We sure see this problem alot. The style of URL you are using ../servlet/someName requires the support of an "invoker" servlet. Look at the web.xml in the ../conf directory - it has a complete explanation.
Bill


Java Resources at www.wbrogden.com
Chris Smith
Ranch Hand

Joined: May 03, 2002
Posts: 42
Incidentally, this is also a non-standard way to invoke servlets, and is supported in Tomcat only as a way to provide backward-compatibility for older conventions on using servlets. Modern webapps should use servlet-mapping entries in web.xml instead.
Grady Jamyson
Ranch Hand

Joined: Aug 04, 2002
Posts: 42
Could you make examples that explan servlet-mapping?
Thanks.
Chris Smith
Ranch Hand

Joined: May 03, 2002
Posts: 42
Sure. In web.xml, you have a section that says:
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>com.mypackage.MyServletClass</servlet-class>
</servlet>
And then a section that says:
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/list</url-pattern>
</servlet-mapping>
Now, if your servlet protocol, host info, and context URI consists of http://localhost:8080/myapp, the URL pattern handled by this servlet will be http://localhost:8080/myapp/list
HTH.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
grady,
Please change your name to be compliant with JavaRanch's naming policy. It should not be obviously fictitious.
Your displayed name should be 2 separate names with more than 1 letter each. We really would prefer that you use your REAL name.
You can change your name: here.
Thanks,
Cindy


"JavaRanch, where the deer and the Certified play" - David O'Meara
Ryan Bailey
Ranch Hand

Joined: Feb 26, 2002
Posts: 134
We sure see this problem alot. The style of URL you are using ../servlet/someName requires the support of an "invoker" servlet. Look at the web.xml in the ../conf directory - it has a complete explanation.
Bill

This is true. I believe with the newer versions of Tomcat this servlet invoker comes disabled out of the box.
If you enable this feature you shouldn't have any problems accessing the servlet the way you are doing it.
Cheers,
Ryan


SCJP 1.4, SCWCD
Java: The power, elegance, and simplicity of a hand grenade
Carlisia Campos
sanitation engineer
Ranch Hand

Joined: Aug 22, 2001
Posts: 135
I just fixed some similar problems with the help of some ranchers.
Here's one thing that I did that made a difference:
I mapped my servlet url pattern to "/ccservlet" and whenever I called the servlet I used the path "../ccservlet".


Carlisia Campos<br />--------------------------------<br />i blog here: carlisia.com
Grady Jamyson
Ranch Hand

Joined: Aug 04, 2002
Posts: 42
Got it.
Thank you so much!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to run servlet on Tomcat
 
Similar Threads
How to run a servlet using Tomcat?
Is j2ee required for servlet?
how can test my servlet in tomcat
missing application web.xml using defaults
my first servlet please help.