以 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("/"); %>
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服务器处理请求的过程,通过具体实例展示了如何使用request对象获取各种客户端和服务端信息,包括HTTP协议版本、服务器名称、端口号等,并介绍了如何在JSP页面中获取项目的磁盘绝对路径。
771

被折叠的 条评论
为什么被折叠?



