Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

On the ranch - waiting to be lynched  RSS feed

 
david allen
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • 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
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • 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
  • 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???
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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 ]
 
Tina Coleman
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • 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.
 
Mario Rendon
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • 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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!