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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM