Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to run servlet on Tomcat

 
Grady Jamyson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Chris Smith
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you make examples that explan servlet-mapping?
Thanks.
 
Chris Smith
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ryan Bailey
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Carlisia Campos
sanitation engineer
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Grady Jamyson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it.
Thank you so much!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic