首页 > 其他分享 >sendRedirect和forword的区别

sendRedirect和forword的区别

时间:2023-04-25 10:03:55浏览次数:29  
标签:resource 区别 sendRedirect object request method forword servlet response


以下内容来自API文档:

public interface RequestDispatcher

Defines an object that receives requests from the client and sends them to any resource (such as a servlet, HTML file, or JSP file) on the server. The servlet container creates the RequestDispatcher object, which is used as a wrapper around a server resource located at a particular path or given by a particular name.
This interface is intended to wrap servlets, but a servlet container can create RequestDispatcher objects to wrap any type of resource.

/*
参数:
    request - a ServletRequest object that represents the request the client makes of the servlet
    response - a ServletResponse object that represents the response the servlet returns to the client
异常:
    ServletException - if the target resource throws this exception
    IOException - if the target resource throws this exception
    IllegalStateException - if the response was already committed*/
void forward(ServletRequest request,
             ServletResponse response)
      throws ServletException,
             IOException

Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server. This method allows one servlet to do preliminary processing of a request and another resource to generate the response.
For a RequestDispatcher obtained via getRequestDispatcher(), the ServletRequest object has its path elements and parameters adjusted to match the path of the target resource.
forward should be called before the response has been committed to the client (before response body output has been flushed). If the response already has been committed, this method throws an IllegalStateException. Uncommitted output in the response buffer is automatically cleared before the forward.
The request and response parameters must be either the same objects as were passed to the calling servlet’s service method or be subclasses of the ServletRequestWrapper or ServletResponseWrapper classes that wrap them.
This method sets the dispatcher type of the given request to DispatcherType.FORWARD.


标签:resource,区别,sendRedirect,object,request,method,forword,servlet,response
From: https://blog.51cto.com/u_16087831/6223432

相关文章

  • 地址&a和首地址&a[0]的区别
    main(){longa[4]={1,2,3,4};long*p1=(long*)(&a+1);//long*p1=(&a+1);//整个数组地址的下一个long数组的首地址,即存储整个数组a的最后一个字节的下一个字节内存的地址//long*p1=(&a[0]+1);//数组第1个元素地址的下一个long的元素首地址,即数......
  • vue2源码-十四、computed和watch的区别
    computed和watch的区别computed和watch的相同点。底层都会创建一个watcher(用法的区别:computed定义的属性可以在模板中使用,watch不能在视图中使用)computed默认不会执行只有取值的时候才会执行内部会维护一个dirty属性,来控制依赖的值是否发生变化。默认计算属性需要同......
  • Java中Runnable和Callable的区别 Runnable接口
    Callable接口从Java1.0开始,它是java.lang包的一部分从Java1.5开始,它是java.util.concurrent包的一部分。Runnable接口不能返回计算的结果。Callable接口可以返回一个任务的并行处理的结果。Runnable接口不能抛出一个有检查的异常。Callable接口可以抛出一个有检查的异常。......
  • Java中null和“”的区别
    null和空字符串('')虽然都是没有任何内容,但是null却输出空指针异常,因为堆内存中根本就没有这个东西。他们的区别可相当大,虽然都是没有信息,但是null代表堆内存中根本没有这个东西,这个对象不存在,怎么执行indexof操作?空字符串虽然没有信息,但是是有内存空间的,所以null与空字符串主要......
  • useMemo, useCallback, useEffect 三者区别
    useMemo父组件将一个【值】传递给子组件,若父组件的其他值发生变化时,子组件也会跟着渲染多次,会造成性能浪费;useMemo是将父组件传递给子组件的值缓存起来,只有当useMemo中的第二个参数状态变化时,子组件才重新渲染useMemo便是用于缓存该函数的执行结果,仅当依赖项改变后才会重......
  • 命令执行中cat 和tac的区别
    命令执行中cat和tac的区别导引在最近的一道简单的命令执行题目中当使用?c=system('catf');时,发现并不能在网页上显示内容,而如果使用?c=system('tacf');时,内容就能显示出来分析 正则过滤了flag,我们可以使用通配符'*'或者匹配符'?'绕过c?=syetem('ls');//查看一下文......
  • spring boot 过滤器、拦截器的区别和使用
    区别:一、过滤器与拦截器的对比1.使用范围不同:过滤器是基于Servlet,而拦截器是基于Spring的,Spring框架底层又离不开Servlet,所以过滤器也能在Spring体系中使用。2.使用资源不同:拦截器有Spring的支持,能够方便的向容器中注册对象和使用对象,但是过滤器就不能。3.使用场景不同:灵活性上......
  • windows和Linux文件系统区别
    windows和Linux文件系统区别 一、用户操作系统单用户操作系统:指一台计算机在同一时间 只能由一个用户 使用,一个用户独自享用系统的全部硬件和软件资源WindowsXP 之前的版本都是单用户操作系统多用户操作系统:指一台计算机在同一时间可以由 多个用户 使用,多个用户......
  • C++中struct和class的区别 || C++中const和static的作用
    struct和class不同点两者中如果不对成员不指定公私有,struct默认是公有的,class则默认是私有的class默认是private继承,而struct默认是public继承  static不考虑类的情况隐藏。所有不加static的全局变量和函数具有全局可见性,可以在其他文件中使用,加了之后只能在该......
  • 数组为null和数组的长度==0的区别
    //数组为null和数组的长度==0的区别int[]arr=newint[0];int[]arr1=null;//两者之间的区别在于//null是数组类型的空引用//长度为0是指一个空数组//所以,数组只要被new出来,他就不等于null,他只是长度为0而已! ......