`
stoneuu
  • 浏览: 45759 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

重定向中/与请求转发中/的含义

 
阅读更多

 

sendRedirect重定向中起始/的含义是servlet容器的根路径,一般是http://localhost:8080/

请求转发中的起始/是?

 

文档:

 

sendRedirect

void sendRedirect(String location)
                  throws IOException
Sends a temporary redirect response to the client using the specified redirect location URL. This method can accept relative URLs; the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root.

If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.

 

Parameters:
location - the redirect location URL 

 

 

 

 

 

getRequestDispatcher

RequestDispatcher getRequestDispatcher(String path)
Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. A RequestDispatcher object can be used to forward a request to the resource or to include the resource in a response. The resource can be dynamic or static.

The pathname specified may be relative, although it cannot extend outside the current servlet context. If the path begins with a "/" it is interpreted as relative to the current context root. This method returns null if the servlet container cannot return a RequestDispatcher.

The difference between this method and ServletContext.getRequestDispatcher(java.lang.String) is that this method can take a relative path.

 

Parameters:
path - a String specifying the pathname to the resource. If it is relative, it must be relative against the current servlet.
Returns:
a RequestDispatcher object that acts as a wrapper for the resource at the specified path, or null if the servlet container cannot return a RequestDispatcher

 

 

分享到:
评论

相关推荐

    Nginx 根据URL带的参数转发的实现

    Nginx通过配置文件中的location指令来定义不同的请求匹配规则,并且可以对这些规则应用不同的处理策略,比如直接返回静态资源、重定向请求到其他服务器,或者将请求转发给后端服务器处理。在Nginx的配置中,proxy_...

    java web开发中的路径问题

    Servlet中的路径表示与JSP有所不同,主要体现在请求转发和重定向上: - **请求转发**:使用`request.getRequestDispatcher`进行转发时,路径应为相对于Web应用根目录的路径,如`"/dir1/c.jsp"`。 - **重定向**:在...

    Javaweb学习小结.docx

    请求转发在同一请求中实现页面间的导航,浏览器地址栏不会改变,而请求包含则是将一个Servlet的响应嵌入到另一个Servlet的响应中。请求重定向则会导致浏览器发起新的请求,地址栏会更新,不共享请求域中的数据。 6....

    sip代码含义sip代码含义

    3xx 系列应答指示客户端需要采取进一步的操作来完成请求,通常涉及地址更改或重定向。 - **300 Multiple Choices**:表示请求的目标有多个选项,每个选项都有自己的地址。客户端可以选择一个合适的地址继续处理。 ...

    java_web开发中的路径问题借鉴.pdf

    在服务器端的请求转发中,"/"代表Web服务器的一个应用,即"http://机器IP:8080/Web应用"。而在服务器端的重定向中,"/"代表Web服务器,即"http://机器IP:8080"。 此外,理解URI(统一资源标识符)、URL(统一资源...

    基于ASP的URL转发系统.zip

    - **重定向逻辑**:根据预设规则或数据库查询结果,决定将用户请求转发到哪个目标URL。 - **会话管理**:可能使用Session对象跟踪用户会话,以便在转发过程中保持状态信息。 - **日志记录**:为了监控和分析转发行为...

    sip协议不同应答码的含义

    - **302 Moved Temporarily**:请求应当被重定向到 Contact 头域中给出的新地址,但这个改变可能是临时的。 4. **重定向(4xx)**: - 4xx 系列应答码通常表示客户端的错误,如 404 Not Found(请求的 URI 未找到...

    JAVA面试题之Forward与Redirect的区别详解

    文中详细介绍了两种请求转发方式的原理和区别,包括请求转发的含义、Forward转发请求的原理、Redirect转发请求的原理等。 请求转发的含义 在JAVA web开发中,请求转发是指服务器端将用户的请求转发给其他信息资源...

    java_web开发中的路径问题定义.pdf

    总结一下,路径的处理在浏览器端、服务器端转发和重定向时有不同的含义: 1. 浏览器端的`/`表示的是整个Web服务器的根,即`http://机器IP:8080`。 2. 服务器端转发时的`/`表示Web服务器上的特定应用,即`http://机器...

    jsp课堂笔记2

    转发保持了请求的上下文,之前的request、session中的数据仍然可用。 在JSP中,符号“/”具有特定含义: 1. 在JSP或HTML文件中,"/"通常表示Web服务器的根目录,例如,它等同于"http://localhost:8080"。 2. 在`...

    自定义Spring Security的身份验证失败处理方法

    虽然它们两个都是非常重要的,但它们具有不同的含义,并在验证请求时应用不同的约束。 身份验证是指验证用户的身份,即验证用户名和密码是否与我们的应用程序识别的用户名和密码相匹配。授权是指验证用户是否有权...

    web路径1

    在请求转发和XML文件映射时,服务器处理的"/"通常指的是Web应用的根路径;而在超链接、表单`action`属性或者请求重定向时,浏览器处理的"/"则指向Web站点的根路径。 此外,`HttpServletRequest`对象提供了几个方法...

    HTTP返回代码表

    - **含义**:请求的资源不再可用,且没有任何已知的转发地址。 - **应用场景**:资源永久不再可用。 - **411 Length Required** - **含义**:服务器拒绝在没有定义Content-Length字段的情况下接受请求。 - **...

    Oracle dept表增删改查(Servlet 网页版)

    请求转发(Request Forwarding)和重定向(Redirecting)是Servlet中两种不同的页面间跳转方式。请求转发发生在服务器端,Servlet接收到请求后,使用`RequestDispatcher`的`forward()`方法将请求转发到另一个资源,...

    深度解析浏览器中输入URL后发生了什么

    4. **Root Server查询**:若LDNS也没有解析结果,请求会被转发至Root Server(根域名服务器)。Root Server负责提供顶级域名服务器的信息,例如.com、.cn等。 5. **顶级域名服务器查询**:根据根域名服务器提供的...

    http状态码

    - **410 Gone**:请求的资源在服务器上已经不再可用,并且没有任何已知的转发地址。 - **411 Length Required**:服务器拒绝在没有定义Content-Length头的情况下接受请求。 - **412 Precondition Failed**:服务器在...

Global site tag (gtag.js) - Google Analytics