• 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之间的路径不同,这个路径是访问路径转发.

  • 相关阅读:
    osgearth 编译日志
    osg Error osgearth_viewerd fails with "Loaded scene graph does not contain a MapNode
    多自由度机械臂模拟-吊绳伸缩
    多自由度机械臂模拟7
    osgViewer
    多自由度机械臂模拟6
    多自由度机械臂模拟5
    多自由度机械臂模拟4
    多自由度机械臂模拟3
    多自由度机械臂模拟2
  • 原文地址:https://www.cnblogs.com/LVowe/p/13202793.html
Copyright © 2020-2023  润新知