Request.getRequestURL

getRequestURI()就相当于你在写一个JSP页面的时候会有这样的东西"action=‘/WebRoot/xxx‘"这个方法就是获得‘/WebRoot/xxx‘,也就是说它会得到一个相对地址
而getRequestURL()会得到一个完整的URL地址,也就是绝对的绝对地址

Request.getRequestURL返回的是请求的全部,包括Http协议,端口号,servlet名字和映射路径,但它不包含请求参数。
request.getRequestURI得到的是request URL的部分值,并且web容器没有decode过的

Java code

<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->getRequestURL:
public java.lang.StringBuffer getRequestURL()
Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters.

Because this method returns a StringBuffer, not a string, you can modify the URL easily, for example, to append query parameters.

This method is useful for creating redirect messages and for reporting errors.

Returns:
a StringBuffer object containing the reconstructed URL

getRequestURI:
public java.lang.String 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. The web container does not decode this String. For example:
First line of HTTP request Returned Value
POST /some/path.html HTTP/1.1 /some/path.html
GET http://foo.bar/a.html HTTP/1.0 /a.html
HEAD /xyz?a=b HTTP/1.1 /xyz
To reconstruct an URL with a scheme and host, use HttpUtils.getRequestURL(javax.servlet.http.HttpServletRequest).
Returns:
a String containing the part of the URL from the protocol name up to the query string
See Also:
HttpUtils.getRequestURL(javax.servlet.http.HttpServletRequest)

request.getRequestURI() /jqueryWeb/resources/request.jsp
request.getRequestURL() http://localhost:8080/jqueryWeb/resources/request.jsp
request.getContextPath()/jqueryWeb
request.getServletPath()/resources/request.jsp

注: resources为WebContext下的目录名
      jqueryWeb 为工程名

时间: 2024-09-26 23:26:11

Request.getRequestURL的相关文章

request.getRequestURL()和request.getRequestURI()的区别

request.getRequestURL() 返回全路径 request.getRequestURI() 返回除去host(域名或者ip)部分的路径 request.getContextPath() 返回工程名部分,如果工程映射为/,此处返回则为空 request.getServletPath() 返回除去host和工程名部分的路径 例如: request.getRequestURL() http://localhost:8080/jqueryLearn/resources/request.j

request.getRequestURI() 、request.getRequestURL()

摘要 request.getRequestURI() .request.getRequestURL() .request.getContextPath().request.getServletPath()区别 request.getRequestURI() .request.getRequestURL() .request.getContextPath().request.getServletPath()区别 request.getRequestURI() /jqueryWeb/resource

Request和Response详解

转自:http://zhidao.baidu.com/link?url=8BI0cjlcFdBSJKHTZlpo874eqtbTJoZfrh3miQgM_05RvSER8skPiBc1wSPZtXT8OGGCHfVXFAzAosa6E5HBl_ 内置对象request:请求对象request.getParameter("名字") 获得客户端输入的信息***************request.getParameterValues("名字") 获得客户端输入的一组信

Servlet的request学习笔记

1.Request的常用方法 1.请求行   Get  http://localhost:8080/day09/servlet/req1?username=zs  http/1.1 getMethod(); 获得请求方式 getRequestURL();返回客户端发出请求时的完整URL. getRequestURI(); 返回请求行中的资源名部分. getContextPath(); 当前应用的虚拟目录 /day09_01_request getQueryString() ; 返回请求行中的参数

如何在类中获取request,和网站路径

@RequestMapping(value = "res/testjs") public ModelAndView testjs( ModelMap model ) throws Exception { String path = resService.getRequestPath(); model.put("path", path); return new ModelAndView("res/testjs"); } 上面是调用: 下面是方法:

day03-java web之request、response

请求响应流程图 response 1        response概述 response是Servlet.service方法的一个参数,类型为javax.servlet.http.HttpServletResponse.在客户端发出每个请求时,服务器都会创建一个response对象,并传入给Servlet.service()方法.response对象是用来对客户端进行响应的,这说明在service()方法中使用response对象可以完成对客户端的响应工作. response对象的功能分为以下

jsp九大内置对象之一request

request对象,目的是用来获取客户端的请求. 主要方法有: request.getMethod();                      // 获取提交请求的方式 request.getProtocol();                    // 获取请求的协议 request.getRequestURL();              // 获取请求目标网络路径 request.getServletPath();               // 获取请求目标的在项目中的相对路

getRequestURI,getRequestURL的区别

getRequestURI,getRequestURL的区别 test1.jsp======================= <a href ="test.jsp?p=fuck">跳转到test2</a> test2.jsp======================= <%@ page language="java" import="java.util.*" pageEncoding="gb2312&q

Nginx SSL+tomcat集群,request.getScheme() 取到https正确的协议

转自:http://feitianbenyue.iteye.com/blog/2056357 最近在做一个项目, 架构上使用了 Nginx +tomcat 集群, 且nginx下配置了SSL,tomcat no SSL,项目使用https协议 但是,明明是https url请求,发现 log里面, Xml代码   0428 15:55:55 INFO  (PaymentInterceptor.java:44) preHandle() - requestStringForLog:    { "re