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