JSP中param标签用法实例分析

   2015-10-22 0
核心提示:这篇文章主要介绍了JSP中param标签用法,以实例形式较为详细的分析了param标签的功能、定义与使用技巧,需要的朋友可以参考下

本文实例分析了JSP中param标签用法。分享给大家供大家参考,具体如下:

Jsp中param标签的使用

<jsp:param>操作被用来以"名-值"对的形式为其他标签提供附加信息。它和<jsp:include>、<jsp:forward>、<jsp:plugin>一起使用,方法如下:

复制代码 代码如下:
<jsp:param name="paramName" value="paramValue"/>

其中,name为与属性相关联的关键词,value为属性的值。

1.<jsp:param>与<jsp:include>配合使用

includeAction.jsp

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
  <title>Include</title>
</head>
<body>
  <%double i = Math.random();%>
  <jsp:include page="come.jsp">//加载come.jsp
  <jsp:param name="number" value="<%=i%>" />//传递参数
</jsp:include>
</body>
</html>

come.jsp

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
  <title>come</title>
</head>
<body bgcolor=cyan>
 <Font Size=3>
 <%//获得includeAction.jsp传来的值:
  String str = request.getParameter("number");
double n = Double.parseDouble(str);
%>
  The value form includeAction is:<br> <%=n%>
</Font>
</body>
</html>

2.<jsp:param>与<jsp:forward>配合使用

用户登录示例

login.jsp

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
  <title>Login</title>
</head>
<body>
   //由 checklogin.jsp处理表单数据
  <form action="checklogin.jsp" method="get">
    <table>
      <tr>
       <td>Username:</td>
       <td> //获得参数"user",初始值为null
         <input type="text" name="username"
           value=<%=request.getParameter("user") %>>
       </td>
      </tr>
      <tr>
       <td>Password:</td>
       <td>
         <input type="password" name="password">
       </td>
      </tr>
      <tr>
       <td>
         <input type="submit" value="login">
       </td>
      </tr>
    </table>
  </form>
</body>
</html>

checklogin.jsp

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
  <title>CheckLogin</title>
</head>
<body>
  <%
   //与login.jsp中name="username"对应
    String name = request.getParameter("username");
    //与login.jsp中name="password"对应
String password = request.getParameter("password");
    if (name.equals("admin") && password.equals("admin")) {
  %>
  <jsp:forward page="success.jsp">//跳转至success.jsp
    <jsp:param name="user" value="<%=name%>" />//携带参数"user"
  </jsp:forward>
  <%
  } else {
  %>
  <jsp:forward page="login.jsp">//跳转至login.jsp
    <jsp:param name="user" value="<%=name%>" />//携带参数"user"
  </jsp:forward>
  <%
  }
  %>
</body>
</html>

success.jsp

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
  <title>Success</title>
</head>
<body>
  Welcome,<%=request.getParameter("user")%>//获得参数"user"
</body>
</html>

希望本文所述对大家JSP程序设计有所帮助。

 
标签: JSP param 标签
反对 0举报 0 评论 0
 

免责声明:本文仅代表作者个人观点,与乐学笔记(本网)无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
    本网站有部分内容均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责,若因作品内容、知识产权、版权和其他问题,请及时提供相关证明等材料并与我们留言联系,本网站将在规定时间内给予删除等相关处理.

点击排行