When we interact with the form using a servlet, both the pass-through and the reference often write paths. About the specific servlet's pass-through and the connection parameter I will have the detailed arrangement later, here first tidy up the not commonly used to some httpservletrequest method, these we actually should know.
OK, when we use the MyEclipse new JSP page, the top 2 lines bring out the message saying:
<%string path = Request.getcontextpath (); String basepath = request.getscheme () + "://" + request.getservername () + ":" + request.getserverport () + path + "/";%>
The path here is the beginning of the absolute path we write when we submit the form, which is the project name.
BasePath is the complete path to the entire submission request.
I write a servlet below, the inside call these methods, unified do a collation, although not how to use, but still need to know these methods.
Package Linkin;import Java.io.ioexception;import Java.util.enumeration;import javax.servlet.ServletException; Import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;public class Linkinservlet extends httpservlet{private static final long Serialversionuid = 1L; @Overrideprotected void Doget (HttpServletRequest req, HttpServletResponse resp) throws Servletexception, ioexception{//the context path of the request/linkinsystem.out.println (Req.getcontextpath ());//Request Complete uri/linkin/ LinkinServletSystem.out.println (Req.getrequesturi ());//The full URL of the request http://localhost:8080/linkin/ LinkinServletSystem.out.println (Req.getrequesturl ());//The path of the requested servlet in the project/LINKINSERVLETSYSTEM.OUT.PRINTLN ( Req.getservletpath ());//The requested HTTP request type GETSYSTEM.OUT.PRINTLN (Req.getmethod ());//The Requested protocol type HTTPSYSTEM.OUT.PRINTLN ( Req.getscheme ())///Requested host IPLOCALHOSTSYSTEM.OUT.PRINTLN (Req.getservername ());//Port of the requested host 8080SYSTEM.OUT.PRINTLN ( Req.getserverport ());//The information inside the header of the request, here is the Get method, so it's all nUllenumeration enumeration = Req.getheadernames (); while (Enumeration.hasmoreelements ()) {String header = (string) Enumeration.nextelement (); System.out.println (header + ":" + req.getheader ("header"));/* host:nullconnection:nullcache-control:nullaccept:nulluser-agent:nullaccept-encoding:nullaccept-language:null*/} } @Overrideprotected void DoPost (HttpServletRequest req, HttpServletResponse resp) throws Servletexception, IOException {This.doget (req, resp);}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Servlet--httpservletrequest some ways about paths