• RequestDispatcher接口include方法


    原文地址: RequestDispatcher接口include方法

    在这里插入图片描述


    web.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
             version="4.0">    
    
        <servlet>
            <servlet-name>IncludedServlet</servlet-name>
            <servlet-class>com.RequestDispatcher.IncludedServlet</servlet-class>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>IncludedServlet</servlet-name>
            <url-pattern>/IncludedServlet</url-pattern>
        </servlet-mapping>
    
        <servlet>
            <servlet-name>IncludingServlet</servlet-name>
            <servlet-class>com.RequestDispatcher.IncludingServlet</servlet-class>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>IncludingServlet</servlet-name>
            <url-pattern>/IncludingServlet</url-pattern>
        </servlet-mapping>
    
    </web-app>

    IncludingServlet.java:

    public class IncludingServlet extends HttpServlet {
    
        public void doGet(HttpServletRequest request,
                          HttpServletResponse response)
                throws ServletException, IOException {
    
            response.setContentType("text/html;charset=utf-8");
    
            PrintWriter out=response.getWriter();
            RequestDispatcher dispatcher=request.getRequestDispatcher("/IncludedServlet?pl=abc");
            out.println("before including"+"<br>");
            dispatcher.include(request,response);
            out.println("after including");
        }
        public void doPost(HttpServletRequest request,
                           HttpServletResponse response)
                throws ServletException,IOException{
            this.doGet(request,response);
        }
    }

    在这里插入图片描述
    IncludedServlet.java:

    public class IncludedServlet extends HttpServlet {
    
        public void doGet(HttpServletRequest request,
                          HttpServletResponse response)
                throws ServletException, IOException {
    
            response.setContentType("text/html;charset=utf-8");
            response.setCharacterEncoding("utf-8");
            PrintWriter out=response.getWriter();
            out.println("中国"+"<br>");
            out.println("URI:"+request.getRequestURI()+"<br>");
            out.println("QueryString:"+request.getQueryString()+"<br>");
            out.println("parameter pl"+request.getParameter("pl")+"<br>");
    
        }
        public void doPost(HttpServletRequest request,
                           HttpServletResponse response)
                throws ServletException,IOException{
            this.doGet(request,response);
        }
    }
  • 相关阅读:
    [离散数学]集合3.1、3.2、3.3
    Hadoop YARN ResourceManager 未授权访问漏洞复现
    dns域传送漏洞
    文件包含漏洞详解
    XXE漏洞详解
    常见cms
    IP地址详解
    帧详解
    IP包头内容详解
    SSRF漏洞详解
  • 原文地址:https://www.cnblogs.com/hfultrastrong/p/14259466.html
Copyright © 2020-2023  润新知