permaculture playing cards*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Basic doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Basic doubt" Watch "Basic doubt" New topic
Author

Basic doubt

Lalitha Chandran
Ranch Hand

Joined: Jul 03, 2003
Posts: 92
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

Joined: Jul 02, 2003
Posts: 247
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.


SCJP 1.4, SCWCD, SCBCD, IBM XML, IBM Websphere 285, IBM Websphere 287
Lalitha Chandran
Ranch Hand

Joined: Jul 03, 2003
Posts: 92
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

Joined: Mar 12, 2003
Posts: 42
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

Joined: Jul 02, 2003
Posts: 247
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

Joined: Jul 03, 2003
Posts: 92
Hi Cyril,
Thanks a lot for responding. It is now working after I uncommented the invoker portion from web.xml.
Thank you
Lalitha Chandran
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Basic doubt