Desidero ottenere l'URL radice della mia applicazione Web da uno dei servlet.Root URl del servlet
Se distribuisco la mia applicazione in "www.miodominio.com", desidero ottenere l'url di root come "http://www.mydomain.com".
Stessa cosa se schiero nel server Tomcat locale con 8080 porta dovrebbe dare http://localhost:8080/myapp
Qualcuno può dirmi come ottenere l'URL radice della mia applicazione web da 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
}
}
String = RootURL request.getRequestURL() toString() sostituire (request.getRequestURI(), "");.. – Sllouyssgort
@Sllouyssgort non funziona perché 'getRequestURI()' include 'myapp' – Black