• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

On the ranch - waiting to be lynched

 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could someone please give me a little insight into how I get my servlet to run
I have written a servlet and much to my astonishment it compiles!!
Now I have put the class file in
ROOT\WEB-INF\hello.class
but when I user the URL http://localhost/servlet/hello
I get an error message. Do I have to edit the web.xml file. If so you could someone please post the code.
thanks
david
 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it'd be nice and really really helpful if you can show us the error message...
 
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
sorry the error that I receive is as follows

exception
javax.servlet.ServletException: Cannot allocate servlet instance for path /servlet/hello
root cause
java.lang.IllegalAccessException: Class org.apache.catalina.core.StandardWrapper can not access a member of the hello with modifiers ""

Please note I have set my classpath variables. As jsp pages run fine and servlets compile. I just dont know where to put them. Do I have to edit web.xml???
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should place your servlet in:
'ROOT\WEB-INF\classes\hello.class'
and put these lines in 'web.xml'
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>hello</servlet-class>
</servlet>
Rene
[ October 09, 2002: Message edited by: Rene Larsen ]
 
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
No I still get the same error. This is getting to be too much.
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have any 'package' statement in the top of 'hello.java'?
If no, then try to modify the 'web.xml' like this:

Now you should be able to call the servlet like this:
http://127.0.0.1/hello
Rene
[ October 10, 2002: Message edited by: Rene Larsen ]
 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been wrestling with the same issue in Tomcat 4.1. Supposedly, if one creates a new context (directory within /webapps), on Tomcat startup, that context will get picked up, and if there's no web.xml file within its WEB-INF directory, then the default web.xml will be used, which should allow us to access our servlets using a URL like:
http://host/context/servlet/[package info.]servletName
without muddling with web.xml files or server.xml files. Practically speaking, I've had to have a web.xml file in my local context area with both a <servlet> definition and a <servlet-mapping> definition. So, my web.xml for a HelloServlet servlet looks like this:

This means, though, that any request to my servletConnect context (even static HTML files within the context) maps to my servlet. I could update the URL pattern to be more specific, but am not concerned about it for my test purposes.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry if im tooo easy with this explanation..

Fist ..
in old web server ( with servlet usage)
there used to be a servlet directory where all the servlets ( as cgi used to ) shoud be putted ..

a special directory where all the servlets should go .
and of course the same is Servlet..
later with the comming of the "Application Servers" there's no such directory ..
there's sometig called servlet context . and
there's a new role called WEB Application .
the web application consists in a structure you should follow to make your servlets and your whole application to work .

the structure ( you should create) is the following .
WEB-INF
|______classes
"CASE SESITIVE!"
iside of WEB-INF directory there should be a web.xml .
wich maps . URL's to your servlet classes .
wich are putted under the classes directory

if you use packages you sould also use subdirectories as you use in java ..
in older posts they explain the web.xml contents .

so put your files under the correct structure and
enjoy your sevlets ..
Grettings . .

PD.
Application servers are the context creators for your servlet.
yo could use tomcat it's free and comes with some web applications you coudl use as example

www.apache.org
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic