Analysis of the method of obtaining url path from jsp
- 2021-11-01 04:17:29
- OfStack
This article illustrates how jsp gets the path of url. Share it for your reference, as follows:
If the URL you requested is http://localhost: 8080/demo/Index. jsp
request.getScheme() // Output: http
request.getServerName() // Output: localhost
request.getServerPort() // Output: 8080
request.getContextPath() // Output: /demo
request.getRequestPath() // Output: /Index.jsp
request.gerRequestURI() // Output: /demo/Index.jsp
request.getRequestURL() // Output: http://localhost:8080/demo/Index.jsp
request.getRealPath("") // Output: D:\apache-tomcat-6.0.10\webapps\demo
I have verified all the above, except that request. getRequestPath () can't be used (it is estimated that this function has been discarded), and other displays are correct.
I hope this article is helpful to everyone's JSP programming.