• JAVA-JSP动作元素之param


    相关资料:
    《21天学通Java Web开发》

    结果总结:
    1.用来传递参数,一般与<jsp:include>、<jsp:forward>联合使用。
    2.<jsp:param name="参数值" value="参数值"/>
    3.name用来设定参数的名字。value用来设定参数的值。

     

    <jsp:include>动作元素搭配<jsp:param>动作元素

    contentDemo.jsp (单参数)

    1 <%@ page language="java" contentType="text/html; charset=gb2312" %>
    2 <h2>被包含页</h2>
    3 <p>接收到的参数</p>
    4 <%
    5   String strAge = request.getParameter("age");//接收参数
    6 %>
    7 <%-- 输出参数内容 --%>
    8 <%="age参数值为:"+strAge %>
    View Code

    param1.jsp

     1 <%@ page language="java" contentType="text/html; charset=gb2312" %>
     2 <html>
     3 <head>
     4   <title>包含JSP文件并传递参数</title>
     5 </head>
     6 <body>
     7   使用include动作元素包含一个包含JSP文件,并传递参数<br>
     8   <jsp:include page="contentDemo.jsp">
     9     <jsp:param name="age" value="19"/>
    10   </jsp:include>
    11 </body>
    12 </html>
    View Code

    contentDemo2.jsp (多参数)

     1 <%@ page language="java" contentType="text/html; charset=gb2312" %>
     2 <h2>被包含页</h2>
     3 <p>接收到的参数</p>
     4 <%
     5   String strName = request.getParameter("name");//接收参数
     6   String strAge = request.getParameter("age");//接收参数
     7   String strSex = request.getParameter("sex");//接收参数
     8 %>
     9 <%-- 输出参数内容 --%>
    10 <%="name参数值为:"+strName %>
    11 <%="age参数值为:"+strAge %>
    12 <%="sex参数值为:"+strSex %>
    View Code

    params.jsp

     1 <%@ page language="java" contentType="text/html; charset=gb2312" %>
     2 <html>
     3 <head>
     4   <title>包含JSP文件并传递多个参数</title>
     5 </head>
     6 <body>
     7   使用include动作元素包含一个包含JSP文件,并传递多个参数<br>
     8   <jsp:include page="contentDemo2.jsp">
     9     <jsp:param name="name" value="Jame"/>
    10     <jsp:param name="age" value="19"/>
    11     <jsp:param name="sex" value="man"/>
    12   </jsp:include>
    13 </body>
    14 </html>
    View Code

     

    <jsp:forward>动作元素搭配<jsp:param>动作元素

    ForwardedDemo.jsp (单参数)

     1 <%@ page language="java" contentType="text/html; charset=gb2312" %>
     2 <html>
     3 <head>
     4   <title>跳转到的页面</title>
     5 </head>
     6 <body>
     7   <h2>跳转到的页面</h2>
     8   <p>接收到的参数:</p>
     9   <%
    10     String strAge = request.getParameter("age");//接收参数
    11   %> 
    12 <%-- 输出参数内容 --%>
    13 <%="age参数值为:" + strAge %>
    14 </body>
    15 </html>
    View Code

    paramforward.jsp

     1 <%@ page language="java" contentType="text/html; charset=gb2312" %>
     2 <html>
     3 <head>
     4   <title>跳转并传递参数</title>
     5 </head>
     6 <body>
     7   使用forward动作元素跳转到另一个JSP文件,并传递参数<br>
     8   <jsp:forward page="ForwardedDemo.jsp">
     9     <jsp:param name="age" value="19"/>
    10   </jsp:forward>
    11 </body>
    12 </html>
    View Code

    ForwardedDemo2.jsp (多参数)

     1 <%@ page language="java" contentType="text/html; charset=gb2312" %>
     2 <html>
     3 <head>
     4   <title>跳转到的页面</title>
     5 </head>
     6 <body>
     7   <h2>跳转到的页面</h2>
     8   <p>接收到的参数:</p>
     9   <%
    10     String strName = request.getParameter("name");//接收参数
    11     String strAge = request.getParameter("age");//接收参数
    12     String strSex = request.getParameter("sex");//接收参数
    13   %> 
    14 <%-- 输出参数内容 --%>
    15 <%="name参数值为:" + strName %>
    16 <%="age参数值为:" + strAge %>
    17 <%="sex参数值为:" + strSex %>
    18 </body>
    19 </html>
    View Code

    paramforward2.jsp

     1 <%@ page language="java" contentType="text/html; charset=gb2312" %>
     2 <html>
     3 <head>
     4   <title>跳转并传递参数</title>
     5 </head>
     6 <body>
     7   使用forward动作元素跳转到另一个JSP文件,并传递参数<br>
     8   <jsp:forward page="ForwardedDemo2.jsp">
     9     <jsp:param name="name" value="name"/>
    10     <jsp:param name="age" value="19"/>
    11     <jsp:param name="sex" value="man"/>
    12   </jsp:forward>
    13 </body>
    14 </html>
    View Code

     

  • 相关阅读:
    基于perl的网络爬虫
    ios cell展示可滑动的图片
    iOS计算字符串的宽度高度
    swift水波效果
    iOS添加另一个控制器的时候要注意啊
    swift隐藏显示导航栏的底线
    swift集成alamofire的简单封装
    tableview详细介绍
    xmpp xml基本语义
    xmpp SASL 定义
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/7459481.html
Copyright © 2020-2023  润新知