JSP 用户表单的简单实现

 1 <%@ page language="java" contentType="text/html; charset=utf-8"
 2     pageEncoding="utf-8"    import="java.util.*" %>
 3 <%@ page import="java.sql.*" %>
 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 5 <html>
 6 <head>
 7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 8 <title>用户表单</title>
 9 </head>
10 <body>
11 <center>
12     <form action="SetPropertyDemo.jsp" method="post">
13         <table>
14             <tr>
15                 <td colspan="2">用户表单</td>
16             </tr>
17             <tr>
18                 <td>用户名:</td>
19                 <td><input type="text" name="username"></td>
20             </tr>
21             <tr>
22                 <td>&nbsp;&nbsp;码:</td>
23                 <td><input type="password" name="userpassword"></td>
24             </tr>
25             <tr>
26                 <td colspan="2">
27                 <input type="submit" name="提交">
28                 <input type="reset" name="重置">
29             </tr>
30         </table>
31     </form>
32 </center>
33 </body>
34 </html>

这个表单简单实现了用户名+密码的参数传递。

在该页提交了用户名和密码之后,会跳转到另一个页面SetPropertyDemo.jsp,输出提交的用户信息。

SetPropertyDemo.jsp的代码如下:

 1 <%@ page language="java" contentType="text/html; charset=utf-8"
 2     pageEncoding="utf-8"    import="java.util.*" %>
 3 <%@ page import="java.sql.*" %>
 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 5 <html>
 6 <head>
 7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 8 <title>设置JavaBean属性</title>
 9 </head>
10 <body>
11     <jsp:useBean id="user" scope="page" class="chapter7.UserBean"></jsp:useBean>
12     <jsp:setProperty property="*" name="user"/>
13     <%
14         out.println("用户名:"+user.getUsername()+"<br/>");
15         out.println("用户密码:"+user.getPassword());
16     %>
17 </body>
18 </html>

 

posted @ 2016-08-06 22:55  xingzhui  阅读(10340)  评论(0编辑  收藏  举报