zoukankan      html  css  js  c++  java
  • RequestDispatcher.forward() 方法和HttpServletResponse.sendRedirect()方法的区别

    RequestDispatcher.forward() 方法和HttpServletResponse.sendRedirect()方法的区别

    先贴一段代码

        public void logon(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
            
            RequestDispatcher rd=null;
    
            LoginJdbc login=new LoginJdbc();
            Student stu = new Student();
            stu.setNum(request.getParameter("userNum"));
            stu.setPassword(request.getParameter("userPass"));
                
            boolean mark = login.login(stu);                  //获取登入标记
                
            if(!mark){
                response.sendRedirect("2/error.jsp");
            }
            else{
                rd=request.getRequestDispatcher("2/Registration.jsp");
                rd.forward(request,response);
            }            
        
        }

    代码中用到了RequestDispatcher.forward() 方法和HttpServletResponse.sendRedirect()方法,所以我就在思考着俩个方法有什么区别,然后通过运用我的代码,总结了一下表格:

    RequestDispatcher.forward() 方法 HttpServletResponse.sendRedirect()方法
    运行在服务端 运行在客户端
    浏览器url地址不变化

    浏览器url地址变化                 

    转载于:https://www.cnblogs.com/qisong178878915/p/4152094.html

  • 相关阅读:
    Web 应用的 UML 建模与 .NET 框架开发
    UML类详解
    学习Pythod 有感
    树形结构应用技巧
    面向对象的设计原则-类设计原则
    prototype 学习
    php framework kohana 学习2
    用批命令更新数据库
    HashTable
    jquery 调用wcf project
  • 原文地址:https://www.cnblogs.com/twodog/p/12134778.html
Copyright © 2011-2022 走看看