When running struts2, there are times when there are mistakes, especially newbies,
This is the case when the STRUTS2 advanced Pojo access occurs when the S
Warning:
Error setting expression ' User.password ' with value ' [ljava.lang.string;@1cb2dd1 'null for SetProperty (null, "password", [Ljava.lang.string;@1cb2dd1) at OGNL. Ognlruntime.setproperty (Ognlruntime.java:2219)
Similar to the above anomaly, I have just started to encounter this more tangled problem, I would like to say how I resolved it, maybe we met with the different. But there are several places in the middle that need to be noticed, or the above error will arise.
1, the front desk JSP
<Body> <formAction= "<%= path%>/login.action"Method= "POST">User name:<inputtype= "text"name= "User.username"><BR/>Password:<inputtype= "text"name= "User.password"><BR/> <inputtype= "Submit"value= "Login"> </form> </Body>
Note Two places, one is the name of input is written as * *. XX, here is the * * is you behind the action of a class object, lowercase is OK, I here is a user, there is this is name= is not id=, if it is with the ID, it seems to be not transmitted to the action.
2. Action Class
Public classLoginextendsActionsupport { PublicUser GetUser () {returnuser; } Public voidsetUser (user user) { This. user =user; } PrivateUser User =NewUser (); @Override PublicString Execute ()throwsException {System.out.println ("Username=" +user.getusername () + ", password=" +User.getpassword ()); returnSUCCESS; } }
User class
Public classUser {PrivateString username; PrivateString password; PublicString GetUserName () {returnusername; } Public voidSetusername (String username) { This. Username =username; } PublicString GetPassword () {returnpassword; } Public voidSetPassword (String password) { This. Password =password; } }
The user class in the action (hibernate+struts) must be new, and if not new will report null pointers
If it is SSH2, the user in action does not need new, but be aware that in the JSP, the user inuser. Usernname is corresponding to the private user user .
Another is the need to have a Get/set method, the user's Get/set method.
Struts.xml
< Packagename= "Login"extends= "Struts-default"> <Actionname= "Login"class= "Com.ssh2.action.Login"> <resultname= "Success"type= "Redirect">/index.jsp</result> <resultname= "Error"type= "Redirect">/login.jsp</result> </Action> </ Package>
Note that the above points are no problem.
About OGNL. Ognlexception:target is null solution for SetProperty (NULL)