Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How to run servlet on Tomcat

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
sanitation engineer
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it.
Thank you so much!!
 
What's brown and sticky? ... a stick. Or a tiny ad.
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic