HttpServletRequest the client gets the request, all the information in the HTTP request header is encapsulated in this object when the client accesses the server over the HTTP protocol. So we can get the appropriate information from the object Port Request.getserverport (); Get the server name Request.getcontextpath (); Get the project name Request.getcontextpath () ; Gets the servlet path Request.getservletpath (). substring (0,request.getservletpath (). LastIndexOf ("/")); Full path:Http://localhost:8080/iswustserver/iswust/library/borrowRequest.getservername (); System.out.println ("ServerName:" +request.getservername ()); Request.getserverport (); System.out.println ("ServerPort:" +request.getserverport ()); Request.getcontextpath (); System.out.println ("ContextPath" + Request.getcontextpath ()); Request.getservletpath (); System.out.println ("Servletpath" + Request.getservletpath ()); Request.getrequesturi (); System.out.println ("RequestUri" + Request.getrequesturi ()); Request.getrequesturl (); System.out.println ("Requesturl" + Request.getrequesturl ()); /*string beanname = requestpath.substring (Requestpath.indexof ("iswust/") + 7,requestpath.indexof ("iswust/") + 11); */
Summary of methods used to obtain URLs, resource names, etc. in Java httpservletrequest