jsp动作元素基础

<jsp:include> 和<%@ include %>的区别
使用<%@ include %>指令元素,只是将页面的内容静态的包含进来,如果被包含的文件中有jsp代码,则会执行该代码,不管该文件是否为动态文件;
  <%@ page contentType="text/html;charset=utf-8" %>
  <html>
  <head><title>包含了一段jsp代码的txt文件</title></head>
  <body>
    当前日期与时间:<%@ include file="content.txt" %>
  </body>
  </html>
  -----------------
  <%@ page import="java.util.*" %>
  <%=new Date() %>
  <!-- 此时的jsp代码会被执行,显示出时间-->
 
  +++++++++++++++++++++++++++++++++++++++++++
    <%@ page contentType="text/html;charset=utf-8" %>
  <html>
  <head><title>包含了一段jsp代码的txt文件</title></head>
  <body>
    当前日期与时间:<jsp:include page="content.txt" />
  </body>
  </html>
 
  <!-- 此时的jsp代码不会被执行,不能够正常显示时间-->
 
 
  <jsp:param>动作元素
  <jsp:param>动作元素是用来传递参数,一般与<jsp:include>和<jsp:forward>联合使用
  <jsp:param name="参数名" value="参数值" />
  <jsp:param>动作元素包含两个属性,name用来设定传递参数的名称,value用来设定传递参数的值;
  示例代码:-----------------------
  <%@ page contentType="text/html";charset="utf-8" %>
  <html>
  <head><title>包含jsp文件并传递参数</title></head>
  <body>
    <jsp:include page="contentDemo.jsp">
        <jsp:param name="age" value="19" />
    </jsp:include>
  </body>
  </html>
  contentDemo.jsp--------------------------
  <%@ page contentType="text/html";charset="utf-8" %>
  <h2>被包含页面</h2>
  <p>接受到的参数</p>
  <%
    String strAge = request.getParameter("age");
  %>

  <%="age 参数值为:"+strAge%>



  示例代码-------------------------------
  <%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <html>
    <head>
    <title>Insert title here</title>
    </head>
    <body style="font-size:30px;">
        <jsp:forward page="content.jsp">
            <jsp:param value="tom" name="name"/>
            <jsp:param value="19" name="age"/>
            <jsp:param value="man" name="sex"/>
        </jsp:forward>
    </body>
    </html>
    content.jsp---------------------
    <%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" import="java.util.*" %>
    <html>
    <head>
    <title>Insert title here</title>
    </head>
    <body style="font-size:30px;">
        <% Date now = new Date();
        out.print(now);%>
        <%
        String Name = request.getParameter("name");
        String Age = request.getParameter("age");
        String Sex = request.getParameter("sex");
        %>
        <%="name的参数是:"+Name %><br/>
        <%="age的参数是:"+Age %>
        <%="sex的参数是:"+Sex %>
    </body>
    </html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值