zoukankan      html  css  js  c++  java
  • 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 为工程名

  • 相关阅读:
    Centos7上安装docker
    centos如何查看某一目录下每个目录或文件占用磁盘空间大小
    大学毕设参考文献在什么网站搜索
    Spring MVC使用jstl 标签c:forEach 遍历输出双层嵌套List的数据
    JQuery选择器通过click事件获取当前点击对象的id,name,value属性
    利用ajax和servlet实现前后端数据交互(json)
    Java软件工程的弹幕调试原则
    周周总结——时时更新(第4学期,第8周)
    团队软件的NABCD——星遇
    周周总结——时时更新(第4学期,第7周)
  • 原文地址:https://www.cnblogs.com/xiadongqing/p/5205329.html
Copyright © 2011-2022 走看看