How do I dynamically put a link to another servlet under the same WebApp
In a servlet1 , I want to write a link to another servlet2 servlet1 and servlet2 are under the same WebApp I don't want to hardcode the link in the URL...
The problem I encounter is that it seems ServletSpec didn't mention how to get one servlet's <url-pattern> value !!
for example , I set a web-app id to '/' in resin.conf by this :
testServlet's full qualified name is : com.smallufo.k3.webapp.testServlet Another testServlet2's full qualified name is : com.smallufo.k3.webapp.testServlet2
I want to write a link in testServlet to testServlet2 , by not hardcoding the URL in servlet code therefore , I write like this :
but it comes the problem...It cannot work , because it combines like this : 'http://k3.smallufo.com:80/com.smallufo.k3.webapp.testServlet2' In Servlet spec , there is no way to get the URL-PATTERN = '/servlet/' !!!
The only one way I can think of is by using HttpServletRequest.getServletPath() to get '/servlet/com.smallufo.k3.webapp.testServlet' , and process the string to get '/servlet/' but it is too inconvenient !!!
Correct if I am wrong but isnt it a servlet container's job to invoke a servlet based on the <url-pattern> and not the other way around? The method getServletPath gives the path of the servlet that is serving the request. So parsing for /servlet/ in the servlet path wouldnt work unless it was a conincidence that the two servlets have the same servlet path. Consider if your web.xml read this way: