Learn several path information related to java--jsp&servlet--httpservletrequest starting from 0

Source: Internet
Author: User

There are several interfaces to get the path in HttpServletRequest: Getrequesturi/getcontextpath/getservletpath/getpathinfo

These interfaces are different from each other and can be distinguished by this code:

1@WebServlet ("/hello.view")2  Public classFirstservletextendsHttpServlet {3         /*....*/4     protected voidDoget (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException {5         //TODO auto-generated Method Stub6Response.setcontenttype ("Text/html;charset=utf-8");7PrintWriter out =Response.getwriter ();8String name = Request.getparameter ("name");9Out.println (");TenOut.println ("); OneOut.println ("<title>hello servlet </title>"); AOut.println ("); -Out.println ("<body>"); theOut.println ("<br>requesturi:" +Request.getrequesturi ()); -Out.println ("<br>contextpath:" +Request.getcontextpath ()); -Out.println ("<br>servletpath:" +Request.getservletpath ()); -Out.println ("<br>pathinfo:" +request.getpathinfo ()); +Out.println ("</body>"); -Out.println ("); + out.close (); A     } at         /*....*/

The name of this project is Firstservlet, and the output after it is run is as follows:

RequestUri:/firstservlet/hello.view, which is equivalent to the full path of the current page, but does not include the parameter information in the URL.
ContextPath:/firstservlet, this is equivalent to the virtual directory name in IIS
Servletpath:/hello.view, this is actually the name of the page.
Pathinfo:null, this is actually requesturi-contextpath-servletpath, that is, if the servlet is in a subdirectory, then the subdirectory name is shown here.



Learn several path information related to java--jsp&servlet--httpservletrequest starting from 0

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.