About OGNL. Ognlexception:target is null solution for SetProperty (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 '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)

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.