Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

access a servlet usin its name

 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..,


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic