14-about OGNL. Ognlexception:target is null for setProperty (solution for NULL)

Source: Internet
Author: User

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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.