JSP中param动作的实例详解

 更新时间:2017年10月12日 09:44:31   作者:cakin24  
这篇文章主要介绍了JSP中param动作的实例详解的相关资料,希望通过本文能帮助到大家,需要的朋友可以参考下

JSP中param动作的实例详解

一 语法

<jsp:param name="参数名" value="参数值">

常常与<jsp:forward>一起使用,作为其子标签存在。 

二 代码

1、login.jsp

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
  
  <title>My JSP 'login.jsp' starting page</title>
  
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">  
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
    -->
 
 </head>
 
 <body>
  <h1>系统登录</h1>
  <hr>
  <form name="loginForm" action="dologin.jsp" method="post">
   <table>
    <tr>
     <td>用户名:</td>
     <td><input type="text" name="username"/></td>
    </tr>
    <tr>
     <td>密码:</td>
     <td><input type="password" name="password"/></td>
    </tr>
    <tr>
     <td colspan="2"><input type="submit" value="登录"/></td>
    </tr>
   </table>
  </form>
 </body>
</html>

2、dologin.jsp

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
  
  <title>My JSP 'dologin.jsp' starting page</title>
  
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">  
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
    -->
 
 </head>
 
 <body>
  <jsp:forward page="user.jsp">
   <jsp:param value="admin@123.net" name="email"/>
   <jsp:param value="888888" name="password"/>
  </jsp:forward>
 </body>
</html>

3、user.jsp

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
  
  <title>My JSP 'user.jsp' starting page</title>
  
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">  
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
    -->
 
 </head>
 
 <body>
  <h1>用户资料</h1>
  <hr>
  <%
    request.setCharacterEncoding("utf-8");
    String username = "";
    String password = "";
    String email = "";
    if(request.getParameter("username")!=null)
    {
     username = request.getParameter("username");
    }
    if(request.getParameter("password")!=null)
    {
     password = request.getParameter("password");
    }
    if(request.getParameter("email")!=null)
    {
     email = request.getParameter("email");
    }
   
  %>
    用户名:<%=username %><br>
    密码:<%=password %><br>
    电子邮箱:<%=email %><br>
 </body>
</html>
 

三 运行结果

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

相关文章

  • struts2入门Demo示例

    struts2入门Demo示例

    这篇文章主要介绍了struts2入门Demo示例,以一个完整实例形式较为详细的分析了struts2的完整实现方法与详细步骤,具有一定参考借鉴价值,需要的朋友可以参考下
    2015-09-09
  • 详解Hibernate cascade级联属性的CascadeType的用法

    详解Hibernate cascade级联属性的CascadeType的用法

    这篇文章主要介绍了详解Hibernate cascade级联属性的CascadeType的用法的相关资料,需要的朋友可以参考下
    2017-02-02
  • 什么是eclipse,eclipse的意思解析

    什么是eclipse,eclipse的意思解析

    什么是eclipse,eclipse的意思解析...
    2007-12-12
  • web开发中添加数据源实现思路

    web开发中添加数据源实现思路

    这篇文章主要介绍了 web开发中添加数据源实现思路的相关资料,需要的朋友可以参考下
    2017-04-04
  • JSP动态网页开发技术概述

    JSP动态网页开发技术概述

    这篇文章主要介绍了JSP动态网页开发技术概述,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-07-07
  • JSP的include指令的使用方法

    JSP的include指令的使用方法

    这篇文章主要介绍了JSP的include指令的使用方法的相关资料,希望通过本文能帮助到大家,让大家理解掌握这部分内容,需要的朋友可以参考下
    2017-10-10
  • 在JSP页面中动态生成图片验证码的方法实例

    在JSP页面中动态生成图片验证码的方法实例

    今天小编就为大家分享一篇关于在JSP页面中动态生成图片验证码的方法实例,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
    2019-03-03
  • jsp hibernate 数据保存操作的原理

    jsp hibernate 数据保存操作的原理

    当执行到session.save()方法时,Hibernate并不会马上生成insert SQL语句来进行数据的保存,而是当稍后清理session的缓存时才有可能执行insert SQL语句,那么session.save()方法到底会执行哪些步骤呢?
    2008-11-11
  • JavaServlet的文件上传和下载实现方法

    JavaServlet的文件上传和下载实现方法

    下面小编就为大家分享一篇JavaServlet的文件上传和下载实现方法具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2018-02-02
  • JSP教程(一)

    JSP教程(一)

    JSP教程(一)...
    2006-10-10

最新评论