• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Could someone try and explain

 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After days of torment of trying to run my HelloWorldServlet I managed to run my servlet via the backdoor.
I am using Tomcat so I naturally placed my servlet in the ROOT\WEB-INF\classes - which did not work.
I then placed the same HelloWorldServlet in the examples\WEB-INF\classes and accessed via a modified index.html page in the examples directory. It worked
I am unable to figure why this would be the case. It is obivous that the problem was with where the file was placed. Could anyone shed some light on this for me
thanks
Oh and thank you to everyone who replied to my last post.
david
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David,

Welcome to Servlet development, and JavaRanch.

The best thing I can recommend is for you to download and read the servlet specification. Of particular interest in this case, is SRV.9.1 - SRV.9.5, plus SRV.11

This give the 'official' view of what a web application is, the directory structure of a web app, and how servlets 'map' to URLs

The other really great resource is the very large comments that are to be found inside Tomcat's default web.xml at CATALINA_HOME/conf/web.xml and Tomcat's documentation for server.xml, which is how you configure web applications in Tomcat

As a (very) high overview, you want to map your servlet classes to request URLs (in web.xml inside your webapp), and then register your webapp with Tomcat (in server.xml).

URLs:
TC config:
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/index.html
webapp config:
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/context.html
servlet spec:
http://jcp.org/aboutJava/communityprocess/first/jsr053/index.html
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
specifics:

Many tutorials (and some of them have really great other information, so it's hard to dismiss them) still use ROOT directory of Tomcat and use the 'lazy' mapping provided by 'most' (but not all) servlet containers... ie: "just place your servlet class here and call it like http://myserver.com/servlet/servlet.class.name"

While not 'wrong', this is not the best practice.

In fact, if you read web.xml I mentioned to you above, you'll see how Tomcat provides the /servlet/* pattern matching. It's in there in the comments.

What you'd want to do is create your own, web-application specific version of the web.xml file, which maps specific servlets to specific URLs. Then Tomcat can combine the webapplication name plus mapping provided in web.xml to serve the correct servlet.

eg: http://myserver.com/mywebapp/myservlet

if you mapped HelloWorld sevlet to 'myservlet' in the web.xml file in the 'mywebapp' application, then the above URL would invoke that servlet.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David
Saw your posts regarding your Tomcat/Servlet troubles.
What version of Tomcat are you using ? this makes a diff., especially concerning the problems you describe.
I can recommend the www.coreservlets.com site. Has exellent info on basic Tomcat/Servlet/JSP configuration for major Tomcat versions.
And hey - let people know of you progress - preferably in this thread.
Martin
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey david,
i want to give you a shoulder to lean on.
i`m just new in java and i know your feelings very well, but be sure there is a way to make servlet`s run.
don`t give up.

bernd
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David
the response to your problem with your serlvet resides in the web.xml File .
first
you have to know a lttle of XML (Extended Markup Language ) to understand it; but is quite simple as html does ..

the web.xml is a place where you put and describe each servlet in your web application so...

look for the <Servlet Tag ..
and yo will realize that this tag gives a servlet a name; and also search for the ...
<servlet-mapping Tag and it maps . (relates) the servlet (defined previously) to the URL in the web application ..

so your URL will end like this..

http://localhost:8080/webappsname/mapping
Grettings
 
david allen
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your help. I have got it working but I think everyone is right, I need to read up on the web.xml file. I am only new to this and I am working out of a book and that was the first stage - setting up and testing jsp and servlets.
I have uni exams in a couple of weeks so after that I will get back into it.

Thanks again for your help it is much appreciated.
David
 
A feeble attempt to tell you about our stuff that makes us money
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic