一、标签访问法:
- <%@ page language="java" pageEncoding="GBK"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>表单Bean例子2</title>
- <link rel="StyleSheet" href="../../CSS/style.css" type="text/css" />
- </head>
- <body>
- <form action="" method="post">
- <table>
- <tr>
- <td>
- <span class="blue10">用户名:</span>
- </td>
- <td>
- <input type="text" name="mUserName" size="20"><br>
- </td>
- </tr>
- <tr>
- <td>
- <span class="blue10">密 码:</span>
- </td>
- <td>
- <input type="password" name="mPassword" size="20"><br>
- </td>
- </tr>
- <tr>
- <td>
- </td>
- <td>
-
- <input type=submit value="submit"/>
- </td>
- </tr>
- </table>
- </form>
- <jsp:useBean id="user" class="it.zhaozhao.userBean"/>
- <jsp:setProperty name="user" property="name" param="mUserName"/>
- <jsp:setProperty name="user" property="password" param="mPassword"/>
- <hr/>
- 用户名:<jsp:getProperty name="user" property="name"/>
- <br>
- 密 码:<jsp:getProperty name="user" property="password"/>
- </body>
- </html>
二、直接访问法:
- <%@ page language="java" pageEncoding="GBK"%>
- <%@ page import="it.zhaozhao.userBean" %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>表单Bean例子3</title>
- <link rel="StyleSheet" href="../../CSS/style.css" type="text/css" />
- </head>
- <body>
- <form action="" method="post">
- <table>
- <tr>
- <td>
- <span class="blue10">用户名:</span>
- </td>
- <td>
- <input type="text" name="mUserName" size="20"><br>
- </td>
- </tr>
- <tr>
- <td>
- <span class="blue10">密 码:</span>
- </td>
- <td>
- <input type="password" name="mPassword" size="20"><br>
- </td>
- </tr>
- <tr>
- <td>
- </td>
- <td>
-
- <input type=submit value="submit"/>
- </td>
- </tr>
- </table>
- </form>
- <%
- userBean user = new userBean();
- user.setName(request.getParameter("mUserName"));
- user.setPassword(request.getParameter("mPassword"));
- %>
- <hr/>
- 用户名:<%=user.getName()%>
- <br>
- 密 码:<%=user.getPassword()%>
- </body>
- </html>