配置tomcat5.0的端口为:80,应用的context path="",应用结果如下:
System.out.println("request url is: " + request.getRequestURI()); (Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.)
System.out.println("PathInfo is: " + request.getPathInfo());
System.out.println("getQueryString is: " + request.getQueryString());
System.out.println("getPathTranslated()is: " + request.getPathTranslated());
System.out.println("getServletPath() is: " + request.getServletPath()); (Returns the part of this request's URL that calls the servlet. This includes either the servlet name or a path to the servlet, but does not include any extra path information or a query string.在Struts中的有关配置:web.xml中:
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
)
分别得到下面的结果:
request url is: /disGoalContentAction.do
PathInfo is: null
getQueryString is: goalID=619&naviStr=a10
getPathTranslated()is: null
getServletPath() is: /disGoalContentAction.do
配置tomcat5.0的端口为:8080,应用的context path="/learndiary",应用结果如下:
request url is: /learndiary/disGoalContentAction.do
PathInfo is: null
getQueryString is: goalID=313&naviStr=a10
getPathTranslated()is: null
getServletPath() is: /disGoalContentAction.do
从下面的网址可以得到一些有关request header的知识
http://web-sniffer.net/?url=http%3A%2F%2Fwww.learndiary.com%2FdisDiaryContentAction.do%3FsearchDiaryID%3D%26goalID%3D1219%26naviStr%3Da10a21105&submit=Submit&http=1.1&gzip=yes&type=GET&ua=Mozilla%2F4.0+%28compatible%3B+MSIE+6.0%3B+Windows+NT+5.0%3B+.NET+CLR+1.1.4322%29+Web-Sniffer%2F1.0.22
得到客户端IP:getRemoteAddr()
得到客户端主机:getRemoteHost()
得到登录的用户名称(不懂): java.lang.String getRemoteUser()
Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.
?
得到请求头的相关信息:
1)、根据请求头的名称得到字符串形式的值: java.lang.String getHeader(java.lang.String name)
Returns the value of the specified request header as a String.
2)、得到所有请求的名称: java.util.Enumeration getHeaderNames()
Returns an enumeration of all the header names this request contains.
3)、根据请求头的名称得到值(这个值是多个值的集合): java.util.Enumeration getHeaders(java.lang.String name)
Returns all the values of the specified request header as an Enumeration of String objects.
4)、根据请求头的名称得到以整数表示的值: int getIntHeader(java.lang.String name)
Returns the value of the specified request header as an int.
3、一个请求头的例子,(来自:http://www.ericgiguere.com/tools/http-header-viewer.html)
Your Headers
These are the HTTP headers your browser is sending to EricGiguere.com:
Name Value
connection Keep-Alive
referer http://www.google.com/search?sourceid=navclient&hl=zh-CN&ie=UTF-8&rls=RNWE,RNWE:2005-40,RNWE:zh-CN&q=http+header+agent
accept-language en-us
content-length 0
host http://www.ericgiguere.com
accept-encoding gzip, deflate
accept */*
cookie JSESSIONID=3E17AFB8F7BECA9544FC2DB406CE3F8D; __utma=135980773.1817431599.1143352455.1143352455.1143355073.2; __utmb=135980773; __utmc=135980773; __utmz=135980773.1143355073.2.2.utmccn=(organic)|utmcsr=google|utmctr=http+header+agent|utmcmd=organic
user-agent Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)