###request获取请求路径内容的相关方法总结。例如:request.getContextPath()。。。

request.getContextPath():获得“/项目名”;例如最常见的:${pageContext.request.contextPath}/xxxServlet ;

已测实例:

<a href='${pageContext.request.contextPath}/ProductServlet?method=findByCid&cid=" + cat.cid + "'>" + cat.cname + "</a>

========ContextPath:/day51_store68Self


request.getRequestURL():获得完整请求路径名(注意不包括请求参数,如果带参数的话);

request.getRequestURI():只包括项目名及其后面的的 URL部分(也就是web资源路径);

已测实例:

========RequestURI:/day51_store68Self/IndexServlet
========RequestURL:http://localhost:8080/day51_store68Self/IndexServlet


request.getQueryString():问号后面内容。

已测实例:

<a href='${pageContext.request.contextPath}/ProductServlet?method=findByCid&cid=" + cat.cid + "'>" + cat.cname + "</a>

========QueryString:method=findByCid&cid=1


重复一遍:

request.getContextPath():获得“/项目名”;例如最常见的:${pageContext.request.contextPath}/xxxServlet ;
已测实例:
<a href='${pageContext.request.contextPath}/ProductServlet?method=findByCid&cid=" + cat.cid + "'>" + cat.cname + "</a>
========ContextPath:/day51_store68Self

request.getRequestURL():获得完整请求路径名(注意不包括请求参数,如果带参数的话);
request.getRequestURI():只包括项目名及其后面的的 URL部分(也就是web资源路径);
已测实例:
========RequestURI:/day51_store68Self/IndexServlet
========RequestURL:http://localhost:8080/day51_store68Self/IndexServlet

request.getQueryString():问号后面内容。
已测实例:
<a href='${pageContext.request.contextPath}/ProductServlet?method=findByCid&cid=" + cat.cid + "'>" + cat.cname + "</a>
========QueryString:method=findByCid&cid=1


====【2018/4/9 知识补充】:

<%@ page contentType="text/html;charset=GBk" import="java.util.*"%>
<html>
<head>
<title>请求信息</title>
</head>
<body>
<p>使用request对象的方法获取信息</p>
<%
//服务器
String localName=request.getLocalName();
String serverName = request.getServerName();
String localAddr=request.getLocalAddr();
int localPort=request.getLocalPort();
int serverPort = request.getServerPort();%>
<b>服务器</b>:<%= localName %><br/>
<b>服务器端IP</b>:<%= localAddr %><br/>
<b>服务器端口</b>:<%= localPort %><p/>
//客户端信息
String remoteHost=request.getRemoteHost();
String remoteAddr=request.getRemoteAddr();
int remotePort=request.getRemotePort();%>
<b>浏览器端</b>:<%= remoteHost %><br/>
<b>浏览器端IP是</b>:<%= remoteAddr %><br/>
<b>浏览器端口</b>:<%= remotePort %><p/>
<%
//协议相关
String pro=request.getProtocol();
String pro1=request.getScheme();
int len=request.getContentLength();
String type=request.getContentType();
String charEncode=request.getCharacterEncoding();
%>
<b>协议版本</b>:<%= pro %><br/>
<b>协议</b>:<%= pro1 %><br/>
<b>数据内容长度</b>:<%= len %><br/>
<b>数据类型</b>:<%= type %><br/>
<b>字符编码方式</b>:<%= charEncode %><p/>
</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值