Java Request Get Path

Source: Internet
Author: User

Various path information can be obtained from the request object, as in the following example:

Assuming that the requested page is index.jsp and the project is Webdemo, get the various path information about the request object in index.jsp as follows

String path = Request.getcontextpath ();

String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";

String remoteaddress=request.getremoteaddr ();

String Servletpath=request.getservletpath ();

String Realpath=request.getrealpath ("/");

String Remoteuser=request.getremoteuser ();

String Requesturi=request.getrequesturi ();

Out.println ("Path:" +path+ "<br>");

Out.println ("BasePath:" +basepath+ "<br>");

Out.println ("remoteaddr:" +remoteaddress+ "<br>");

Out.println ("Servletpath:" +servletpath+ "<br>");

Out.println ("Realpath:" +realpath+ "<br>");

Out.println ("RemoteUser:" +remoteuser+ "<br>");

Out.println ("RequestUri:" +requesturi+ "<br>");

Results:

Path:/webdemo
basepath:http://localhost:8683/webdemo/
remoteaddr:127.0.0.1
servletpath:/index.jsp
Realpath:d:\apache-tomcat-6.0.13\webapps\webdemo\
Remoteuser:null
requesturi:/webdemo/index.jsp

Java Request Get Path

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.