request URL

 

最近发现记忆力越来越差了,有关request的相关参数总是记不住,用一次查一次,今天发现了一个总结的不错,记下来:


以 Tomcat 服务器“http://localhost:8080/vote/test.jsp ”为例说明:

request.getScheme() —— http
request.getServerName() —— localhost
request.getServerPort() —— 8080
request.getContextPath() —— /vote
request.getProtocol() —— HTTP/1.1
request.getRemoteAddr() —— 127.0.0.1
request.getRemoteHost() —— 127.0.0.1
request.getRemotePort() —— 1316
request.getRequestURI() —— /vote/test.jsp
request.getRequestURL() —— http://localhost:8080/vote/test.jsp
request.getServletPath() —— /test.jsp


JSP页面中取得项目所在磁盘绝对路径:
<% pageContext.getServletContext().getRealPath("/"); %>

你可能感兴趣的:(tomcat,jsp)