First, get the project path:
1)
String path = Request.getcontextpath ():///testmyeclipse
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () + path+ "/";
http://127.0.0.1:8080/TestMyEclipse/
2)
Path is: <c:out value= "${pagecontext.request.contextpath}" ></c:out>
The print result is:/springmvc is the project root path
Second, get the URL address:
Get the URL address of the page:
String URL = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport ();
URL + = Request.getcontextpath ();
URL + = Request.getservletpath () + "?" + request.getquerystring ();
Print out is:
http://localhost:8080/BBS/articleFlat.jsp?pageNo=2
There are two other:
System.out.println (Request.getrequesturi ());
System.out.println (Request.getrequesturl ()):
Print them separately:
/bbs/articleflat.jsp
http://localhost:8080/BBS/articleFlat.jsp
So the above get URL address, including parameters can be written like this:
String URL = request.getrequesturl () + "?" + request.getquerystring ();
--------------------------------------------------------------------------------------------------------------- -------------------------------------
Getting various paths in the Java Web