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 '
Ognl. Ognlexception:target is 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
[Java] view plain copy <body> <form action= "<%= path%>/login.action" method= "POST" > Username: <input type = "text" name = "User.username" ><br/> password: <input type = "text" name = "User.pas Sword "><br/> <input type =" 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
[Java] View plain copy public class login extends actionsupport { public user getuser () { return user; } public void setuser (user user) { this.user = user; } private user user = new user (); @Override public string execute () throws exception { system.out.println ("username=" + User.getusername () + ", password=" +user.getpassword ()); return success; } }
User class
[C-sharp] View plain copy public class user { private string username; private String password; 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; } }
The user class in action must be new, and if not new will report a null pointer (unless you already have spring, let spring do it for you)
Another is the need to have a Get/set method, the user's Get/set method.
STRUTS.XM;
[Java]