假定请求的URL为 http://localhost:8080/news/addNews.do?type=1
java 代码
- request.getMethod(); // GET
- request.getServerName(); // localhost
- request.getServerPort(); // 8080
- request.getLocalAddr(); // 127.0.0.1
- request.getLocalName(); // 127.0.0.1
- request.getLocalPort(); // 8080
- request.getRequestURL(); // http://localhost:8080/news/addNews.do
- request.getRequestURI(); // /news/addNews.do
- request.getContextPath(); // /news
- request.getServletPath(); // /addNews.do
- request.getQueryString(); // type=1
- request.getProtocol(); // HTTP/1.1
- request.getScheme(); // http
- request.getPathInfo(); // null
- request.getPathTranslated(); // null
- request.getAuthType(); // null
- request.getRealPath(); // D:\Tomcat5.5\webapps\news\
注释后是方法的返回值