A sign in the Java entity that the judge is male: Isboy
Package Com.jn.bean;
public class Loginuser {
private int: age;
Private String username;
private String password;
/***
* is male *
/
private Boolean isboy;
Public Loginuser () {
super ();
}
public int getage () {
return age;
}
public void Setage (int.) {
this.age = age;
}
Public String GetUserName () {
return username;
}
public void Setusername (String username) {
this.username = username;
}
Public String GetPassword () {
return password;
}
public void SetPassword (String password) {
this.password = password;
}
public Boolean Isboy () {
return isboy;
}
public void Setboy (Boolean isboy) {
this.isboy = Isboy;
}
}
The Getter,setter method is automatically generated using Eclipse.
The corresponding action is:
Package com.jn.action;
Import Com.jn.bean.LoginUser;
Import Com.opensymphony.xwork2.ActionSupport;
public class Loginverifyaction extends Actionsupport {
private static final long Serialversionuid = 5532496750392156 543L;
Private Loginuser user;
@Override public
String execute () throws Exception {
System.out.println ("User information:");
System.out.println ("Username:" +user.getusername ());
System.out.println ("Password:" +user.getpassword ());
System.out.println ("Age:" +user.getage ());
System.out.println ("Isboy:" +user.isboy ());
return Super.execute ();
}
Public Loginuser GetUser () {
return user;
}
public void SetUser (Loginuser user) {
this.user = user;
}
}
Error:
Warning: Error setting expression ' User.isboy ' with value ' [ljava.lang.string;@863941 '
ognl. NoSuchPropertyException:com.jn.bean.LoginUser.isBoy [Java.lang.IllegalAccessException:Class Ognl. Ognlruntime can not access a member of class Com.jn.bean.LoginUser with modifiers "private") at
Ognl. Ognlruntime.setfieldvalue (ognlruntime.java:1682) at
Ognl. Objectpropertyaccessor.setpossibleproperty (objectpropertyaccessor.java:87) at
Ognl. Objectpropertyaccessor.setproperty (objectpropertyaccessor.java:162) at
Com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty (objectaccessor.java:27) at
Ognl. Ognlruntime.setproperty (ognlruntime.java:2315) at
Ognl. Astproperty.setvaluebody (astproperty.java:127) at
Ognl. Simplenode.evaluatesetvaluebody (simplenode.java:220)
The error message indicates that STRUTS2 did not find the setter method for Isboy because Struts2 thought Isboy setter method name should be Setisboy
Why is there a problem when setting Isboy? Because according to Struts2 's dependency injection rules, the setter method should be a set+ member variable (the first letter becomes uppercase).
I changed the Isboy setter method from Setboy to Setisboy, just fine.
public void Setisboy (Boolean isboy) {
this.isboy = Isboy;
}
Summary : This problem occurs if the attribute to be dependent on injection is a Boolean type and the property name begins with is.
Workaround :
If you use struts2 dependency Injection, the Boolean property name does not start with IS. I modified the method to change the property name from Isboy to boy:
Package Com.jn.bean;
public class Loginuser {
private int: age;
Private String username;
private String password;
/***
* is a male */
private Boolean boy;
Public Loginuser () {
super ();
}
public int getage () {
return age;
}
public void Setage (int.) {
this.age = age;
}
Public String GetUserName () {
return username;
}
public void Setusername (String username) {
this.username = username;
}
Public String GetPassword () {
return password;
}
public void SetPassword (String password) {
this.password = password;
}
public Boolean Isboy () {
return boy;
}
public void Setboy (Boolean boy) {
this.boy = boy;
}
}
The login page to change the User.isboy to User.boy just fine.
Code Download Address
Reprint Address: http://hw1287789687.iteye.com/blog/1949399