• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basic doubt

 
Lalitha Chandran
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I was just wondering if it is possible to call a servlet from the browser directly without declaring it in the web.xml. If yes could someone please tell me how? Or else is this question web server specific?
I have been working with jsp and servlets for quite some time now but I have always called the servlets after I have declared them in the web.xml.
Thank you in advance
Lalitha Chandran
 
cyril vidal
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
With Tomcat at least:
Suppose your webapp is mywebapp and you have a servlet named MyServlet in package com.mycompany, you can call the servlet by this URL:
http://localhost:8080/mywebapp/servlet/com.mycompany.MyServlet
Regards,
Cyril.
 
Lalitha Chandran
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Cyril
Thank you for the response.
But I tried the same thing but couldn't get the output.
This is my folder structure
C:\Tomcat 4.1\webapps\ROOT\com
and I tried calling it from browser without declaring it in web.xml
http://localhost:8080/servlet/com.SimpleServlet
But I get the 404 error. I am using Tomcat 4.1.24
Regards
Lalitha Chandran
 
carl chan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need to call
http://localhost:8080/ROOT/servlet/com.SimpleServlet
instead of
http://localhost:8080/servlet/com.SimpleServlet
hope this help
 
cyril vidal
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your URL :
http://localhost:8080/servlet/com.SimpleServlet is the good one. No ROOT must appear here.
But in order to make it OK, you still have to modify your default file web.xml <%TOMCAT_HOME%>/conf/web.xml by deleting the commentary in the following section:
:
<!-- The mapping for the invoker servlet -->
Delete this <!--
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
Delete this -->
Hope this helps,
Regards,
CyriL
 
Lalitha Chandran
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Cyril,
Thanks a lot for responding. It is now working after I uncommented the invoker portion from web.xml.
Thank you
Lalitha Chandran
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic