根據(jù)表單匹配部分屬性的時(shí)候會(huì)報(bào)空指針異常,求解。
<%@ 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=utf-8">
<title>Insert title here</title>
</head>
<body>
<%--實(shí)例化一個(gè)javabean對(duì)象 --%>
<jsp:useBean id="myUsers" class="com.po.Users" scope="page"/>
<h1>setProperty動(dòng)作元素</h1>
<hr>
<%
request.setCharacterEncoding("utf-8");
%>
<!-- 根據(jù)表單自動(dòng)匹配所有的屬性 -->
<%--<jsp:setProperty property="*" name="myUsers"/>--%>
<!-- 根據(jù)表單匹配所有部分的屬性 -->
<jsp:setProperty property="myUsers" name="password"/>
用戶名:<%=myUsers.getUsername() %><br>
密碼:<%=myUsers.getPassword() %><br>
</body>
</html>
2015-10-16
暈~name寫錯(cuò)了