com.opensymphony.xwork2.ognl.OgnlValueStack warn
警告: Error setting expression 'user.gender' with value '[Ljava.lang.String;@130bf9c'
ognl.OgnlException: target is null for setProperty(null, "gender", [Ljava.lang.String;@130bf9c)
。。。。。
************************************************************************
获得个菜鸟级别的错误!找了很久才发现错在那里了;
原因是使用时写错代码了,
userForm userF;
getUser()和setUser()方法
上面红色部分应该是 写成
userForm user;
getUser()和setUser()
***************************************************************************
index.jsp代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!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>首页</title>
</head>
<body>
请注册:<br>
<s:form action="login">
<s:textfield name="user.username" label="用户名"></s:textfield>
<s:password name="user.password" label="密码"></s:password>
<s:submit value="注册"></s:submit>
</s:form>
</body>
</html>
Loginaction.java代码:
public class Loginaction extends ActionSupport {
private static final long serialVersionUID = 1L;
private UserForm user;
public UserForm getUser() {
return user;
}
public void setUser(UserForm user) {
this.user = user;
}
@Override
public String execute() throws Exception {
try {
System.out.println("============"+user.getUsername());
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
return ERROR;
}
}
*************************************************************
总结:出现上面错误原因有以下几个
1、UserForm类里的数据类型使用错误;
2、使用UserForm时,声明的对象及相应的get\set方法错误,必须要和jsp页面中name="user.username"相对应;