aspose file tools*
The moose likes Servlets and the fly likes Servlet beginners problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet beginners problem" Watch "Servlet beginners problem" New topic
Author

Servlet beginners problem

And Green
Greenhorn

Joined: Sep 28, 2007
Posts: 26
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

Joined: Sep 19, 2007
Posts: 29
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

Joined: Jan 02, 2007
Posts: 65
How is configured your web.xml ?
how the servlet is called, get method or post?
ciao,
gianni
And Green
Greenhorn

Joined: Sep 28, 2007
Posts: 26
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

Joined: Sep 19, 2007
Posts: 29
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

Joined: Sep 28, 2007
Posts: 26
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

Joined: Jan 10, 2002
Posts: 61433
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet beginners problem