This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Servlets and the fly likes On the ranch - waiting to be lynched Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "On the ranch - waiting to be lynched" Watch "On the ranch - waiting to be lynched" New topic
Author

On the ranch - waiting to be lynched

david allen
Ranch Hand

Joined: Sep 27, 2002
Posts: 185
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

Joined: Nov 27, 2001
Posts: 1561
it'd be nice and really really helpful if you can show us the error message...


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
david allen
Ranch Hand

Joined: Sep 27, 2002
Posts: 185
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

Joined: Oct 12, 2001
Posts: 1179

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 ]

Regards, Rene Larsen
Dropbox Invite
david allen
Ranch Hand

Joined: Sep 27, 2002
Posts: 185
No I still get the same error. This is getting to be too much.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

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

Joined: Dec 12, 2001
Posts: 150
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

Joined: Jul 11, 2002
Posts: 24
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
 
GeeCON Prague 2014
 
subject: On the ranch - waiting to be lynched