Javabean使用实例

1.login.jsp

 

<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form name="User" action="loginuser.jsp?mypass=417020" 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><input type="submit" value="登录"></td>
</tr>
</table>
</form>
</body>
</html>

2.loginuser,jsp

 

<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="myUsers" class="javabean.Users"></jsp:useBean>
<h1>setProperty动作元素</h1>
<br>
<!-- 根据表单匹配部分属性 ,且使用request对象参数值赋值 -->
<jsp:setProperty property="password" name="myUsers" param="mypass"/>
<%
request.setCharacterEncoding("utf-8");
%>
用户名:<%=myUsers.getUsername() %><br>
密码:<%=myUsers.getPassword() %><br>
<!-- 根据表单匹配部分属性 -->
<jsp:setProperty property="username" name="myUsers"/>
<%
request.setCharacterEncoding("utf-8");
%>
用户名:<%=myUsers.getUsername() %><br>
密码:<%=myUsers.getPassword() %><br>
<!-- 根据表单自动匹配所有属性 -->
<jsp:setProperty property="*" name="myUsers"/>
<%
request.setCharacterEncoding("utf-8");
%>
用户名:<%=myUsers.getUsername() %><br>
密码:<%=myUsers.getPassword() %><br>

 

<%--使用getProperty方法获取属性值 --%>
用户名:<jsp:getProperty property="username" name="myUsers"/><br>
密码:<jsp:getProperty property="password" name="myUsers"/><br>
</body>
</html>


运行截图:

 

 

 

posted @ 2020-11-16 20:00  CherriesOvO  阅读(333)  评论(0编辑  收藏  举报