我想从一个servlet获取我的Web应用程序的根URL.
如果我在"www.mydomain.com"中部署我的应用程序,我想获得像" http://www.mydomain.com " 这样的根URL .
如果我将它部署在具有8080端口的本地tomcat服务器中它应该给予同样的事情 http://localhost:8080/myapp
谁能告诉我如何从servlet获取我的Web应用程序的根URL?
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
}
}
Run Code Online (Sandbox Code Playgroud)