动作元素

本文详细介绍了JSP中的动态包含技术,通过实例展示了如何使用<jsp:include>指令来动态加载另一个JSP文件,并传递参数。同时,文章还对比了页面转向的两种方式:页面转向与转发,说明了它们在实现过程中的不同之处。

动态包含:包含的是对方的输出结果,分别解释为不同的servlet。

动态包含实例:

(1)header.jsp:


    <%String text = request.getParameter( "text" );%>

    <center>

        <h1>        

        <font color="blue">

         <%if( text != null ){ %>                   

            <h1><%=text%></h1>

         <%}else{ %>

            <h1>Welcome to kettas</h1>

         <%} %>

        </font>

        </h1>   

    </center>

(2) body.jsp :


    <%@page contentType="text/html" %>

        <html> 

        <body> 

<!-- 相当于<jsp:include page="/header.jsp?name=This is param"/> -->                    

    <jsp:include page="/header.jsp">

        <jsp:param name="text" value="This is param"/>

            </jsp:include>  

            <h1>This is body</h1> 

            <% 

                for(int i = 0 ; i< 3 ; i++ ){

            %>

            <h2><%= new java.util.Date() %></h2> 

            <%

                }

            %>                    

            <%

                for( int i =0 ; i < 3 ; i++ ){

                    out.println( "<h2>" + new java.util.Date() + "</h2>" ) ;

                }

            %>

            </body>

        </html> 

    <jsp:forward page="/b.jsp" />

        页面转向 : 相当于servlet中的"接力棒"转向, 是在同一个连接中的页面转向.

    <% response.sendRedirect("/a.jsp"); %>

页面转向:连接已经换了一个。

转载于:https://www.cnblogs.com/yuyu666/p/9743835.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值