I want to get the root url of my web application from one of the servlet.
If I deploy my application in "www.mydomain.com" I want to get the root url like "http://www.mydomain.com".
Same thing if I deploy it in local tomcat server with 8080 port it should give http://localhost:8080/myapp
Can anyone tell me how to get the root URL of my web application from servlet?
public class MyServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String rootURL="";
//Code to get the URL where this servlet is deployed
}
}
question from:
https://stackoverflow.com/questions/1629102/root-url-of-the-servlet 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…