zoukankan      html  css  js  c++  java
  • Web_Servlet之间请求转发

    Servlet2

    @WebServlet(urlPatterns = "/aa")
    public class JspService extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request,response);
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
            //设置键值对
    
            request.setAttribute("name","张三丰");
    
            //进行页面跳转
            request.getRequestDispatcher("/demojsp.jsp").forward(request,response);
    
        }
    }

    Servlet1

    @WebServlet(urlPatterns = "/one")
    public class ServletOne extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request,response);
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
            //以键值对存储数据
            request.setAttribute("name","风清扬");
    
            //请求跳转
            request.getRequestDispatcher("/two").forward(request,response);
        }
    }

    Servlet2 和 Servlet1之间的请求转发关键代码是

    request.getRequestDispatcher("/two").forward(request,response);

    关键部分是 "/two" 这个路径和Servlet与JSP之间的路径不同,这个路径是访问路径转发.

  • 相关阅读:
    hdu 5072 Coprime (容斥)
    洛谷 P1411 树 (树形dp)
    Tr/ee AtCoder
    sys.path
    uname
    sys.platform
    Eclipse Basic
    Eclipse Color Theme
    Pydev
    scons
  • 原文地址:https://www.cnblogs.com/LVowe/p/13202793.html
Copyright © 2011-2022 走看看