e1055. passing parameters to another jsp page.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 42 行

TXT
42
字号
An include action (see e1054 Including a File in a JSP Page) executes the included JSP page and appends the generated output onto its own output stream. Request parameters parsed from the URL's query string are available not only to the main JSP page but to all included JSP pages as well. It is possible to temporarily override a request parameter or to temporarily introduce a new request parameter when calling a JSP page. This is done by using the jsp:param action. 
In this example, param1 is specified in the query string and is automatically made available to the callee JSP page. param2 is also specified in the query string but is overridden by the caller. Notice that param2 reverts to its original value after the call. param3 is a new request parameter created by the caller. Notice that param3 is only available to the callee and when the callee returns, param3 no longer exists. Here is the caller JSP page: 

    <html>
    <head></head>
    <body>
    
    <jsp:include page="callee.jsp" />
        <jsp:param name="param2" value="value2" />
        <jsp:param name="param3" value="value3" />
    </jsp:include>
    
    Caller:
    param1: <%= request.getParameter("param1") %>
    param2: <%= request.getParameter("param2") %>
    param3: <%= request.getParameter("param3") %>
    
    </body>
    </html>

Here is the JSP page being called: 
    Callee:
    param1: <%= request.getParameter("param1") %>
    param2: <%= request.getParameter("param2") %>
    param3: <%= request.getParameter("param3") %>

If the example is called with the URL: 
    http://hostname.com?param1=a&param2=b

the output would be: 
    Callee:
    param1: a
    param2: value2
    param3: value3
    
    
    Caller:
    param1: a
    param2: b
    param3: null

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?