This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Running Simple Servlets

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 25850
184
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic