aspose file tools*
The moose likes Tomcat and the fly likes Running Simple Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Running Simple Servlets" Watch "Running Simple Servlets" New topic
Author

Running Simple Servlets

Phil Boss
Greenhorn

Joined: Oct 14, 2002
Posts: 4
I have installed Tomcat 4.1.12 on Red Hat Linux 7.2. Starts OK. Runs all the examples.
I created the new web application:
$CATALINA_HOME/webapps/test
./test/index.jsp
./test/WEB-INF
./test/WEB-INF/web.xml
./test/WEB-INF/classes
./test/WEB-INF/classes/HelloWorld/Example.class
I added the <Context> entry in server.xml within the <host></host> tags. index.jsp runs just fine.
If I try to execute the servlet from the index.jsp page or by
http://localhost:8080/test/servlet/HelloWorldExample
I keep getting the HTTP Status error 404:
"The requested resource (/servlet/HelloWorldExample) is not available."
I'm at wit's end. Can somone help?
Thanks,
Phil
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Try call it like this: http://localhost:8080/test/servlet/HelloWorld.Example
or try add this to 'web.xml' in 'test/WEB-INF/':
<servlet>
<servlet-name>Example</servlet-name>
<servlet-class>HelloWorld.Example</servlet-class>
</servlet>
Then you should call it like this: http://localhost:8080/test/servlet/Example
Rene
[ October 14, 2002: Message edited by: Rene Larsen ]

Regards, Rene Larsen
Dropbox Invite
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16055
    
  21

As a security risk, the "/servlet/" technique of invoking servlets has been deprecated. It's better if you set up a servlet declaration + URL mapping in the web.xml file.


Customer surveys are for companies who didn't pay proper attention to begin with.
Phil Boss
Greenhorn

Joined: Oct 14, 2002
Posts: 4
Rene -
Thanks for your response. The name of the servlet is "HelloWorldExample.class". I've tried shortening the class name and I still get the same problem. I've also already added the <servlet></servlet> declaration to the web.xml file. Have any other suggestions?
Phil
Tim -
thanks for your response. I understand the security risk of the "/servlet/" technique. I am just trying to get a servlet to execute. Would you have an example of a servlet declaration +URL mapping that I could look at?
Phil
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Do you have any 'package' in the top of your 'HelloWorldExample'?
If not the servlet declaration + URL mapping will look like this:

Now you call your servlet like this: http://127.0.0.1:8080/HelloWorldExample
Rene
[ October 14, 2002: Message edited by: Rene Larsen ]
Phil Boss
Greenhorn

Joined: Oct 14, 2002
Posts: 4
Rene -
Thanks for the URL mapping example. A few minor tweaks of the filenames and voila! Problem solved.
Thanks, again.
Phil Bossardet
Rajesh V Rao
Greenhorn

Joined: Oct 17, 2002
Posts: 1
This entry in web.xml will take care of deprecated "servlet" thing, for all servlets.

<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
looks like a cool solution.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running Simple Servlets