This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes access a servlet usin its name 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 "access a servlet usin its name" Watch "access a servlet usin its name" New topic
Author

access a servlet usin its name

Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

I have a big doubt here, I have the simplest deploys file ever.


the application is in the tomcat's webapps directory like this :
tomcat
|- webapps
|- mytest
|- WEB-INF
....

and I try to access this with my browser with the URL : http://localhost:8080/mytest/MyWerver, but this fails. It seams that i can not access a servlet by using its name. The only ways to access the servlet is tu use a servlet-mapping node. So my question is :
It is possible to access a Servlet by using (only) its name ?

Thanks,
M


SCJP, SCJD, SCWCD, OCPJBCD
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
this is a discouraged practice and most
web containers do not allow this by default. Using a serlvet mapping is the standard.
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Hi Michael,

Thanks for your answer, but I still have one question how I can configurate the container to allow this ?

Regards,
M
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
When you said by name I thought you wanted to access the servlet by class name (which is discouraged)

You need to add a servlet maping to match your servlet name entry. I have supplied some of these pairs for you to look at. Notice each servlet tag has a corresponding servlet-mapping tag. It is the servlet-name tag that ties them together. Then you can access the servlet by using the url-mapping pattern. For example, the pattern host/web root/jstltest will match the
<url-pattern>/jstltest</url-pattern>
which is tied to <servlet-name>JSTLTagTestServlet</servlet-name>
which is tied to the actual class <servlet-class>com.sparky.servlet.JSTLTagTestServlet</servlet-class>
</servlet>

You are missing the servlet mapping..,


 
It is sorta covered in the JavaRanch Style Guide.
 
subject: access a servlet usin its name