This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Running Simple Servlets

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Saloon Keeper
Posts: 21240
137
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Phil Boss
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rene -
Thanks for the URL mapping example. A few minor tweaks of the filenames and voila! Problem solved.
Thanks, again.
Phil Bossardet
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Get me the mayor's office! I need to tell her about this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!