Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet beginners problem

 
And Green
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I'm trying to run servlets using apache tomcat.

The examples that come packaged with Apache work when I put http://localhost:8080/examples/servlets/servlet/HelloWorldExample in as the URL fpr example.

If I add my own java class to the same directory as this example however ie \Tomcat 6.0\webapps\examples\WEB-INF\classes and use the URL
http://localhost:8080/examples/servlets/servlet/MyOwnServletClass I get an HTTP 404 error saying that my servlet is not available.

Does anyone please have some tips on whether I'm using the wrong directory or possibly have a classpath issue. The only Apache realted environment variable I have set currently is a PATH to ..\Tomcat 6.0\bin.

Apologies if my error is obvious.

Any help much appreciated.
 
Mladen Grabowsky
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone please have some tips on whether I'm using the wrong directory or possibly have a classpath issue.

My tip: read the servlet spec.

Then add mappings for your servlet in the web.xml
 
gianni ipez
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is configured your web.xml ?
how the servlet is called, get method or post?
ciao,
gianni
 
And Green
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servlet is using the get method:


The Web XML file is here (sorry its big):


[BPSouther: Added UBB Code tags]
[ October 17, 2007: Message edited by: Ben Souther ]
 
Mladen Grabowsky
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't mapped the servlet.

You have to map a class to a servlet name


then that servlet name has to be mapped to an url

This is just an example, in real life you do not map servlets to the /servlets/... url.
[ October 15, 2007: Message edited by: Mladen Grabowsky ]
 
And Green
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats great, worked a treat, thanks for you time on that one.

Is it the case then that I have to modify web.xml, every time, to create a servlet? seems like a bit of a pain and I expect that file is going to get pretty big!

One last thing, when you say, in reality you don't have to map to "servlets/" this is just an example, I'm not sure what you mean. Do you mind just giving a quick explanation. All the other servlets in the web.xml file provide paths that include the servlets directory.

Thanks again.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by And Green:
Is it the case then that I have to modify web.xml, every time, to create a servlet? seems like a bit of a pain and I expect that file is going to get pretty big!

That's what Front Controllers are for. Perhaps this article might be helpful.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic