This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Servlet beginners problem  RSS feed

 
Greenhorn
Posts: 26
  • 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.
 
Greenhorn
Posts: 29
  • 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
 
Ranch Hand
Posts: 65
  • 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
  • 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
  • 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
  • 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.
 
Marshal
Posts: 67192
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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.
 
I just had the craziest dream. This tiny ad was in it.
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!