The problem that struts2/jsp uses form or js to submit requests and encapsulate boolean values

Source: Internet
Author: User

Struts2 submits a request using form or js to encapsulate the Boolean value.

On JSPCode
<Form name = "searchform" Action = "">
<Input id = "searchinfo. ishighsearch" name = "searchinfo. ishighsearch" value = "true"

Type = "hidden"/>

Then, use struts2 to encapsulate parameters in Vo bean. The Bean class name is searchinfo. java.
This class has attributes.

 

Private Boolean ishighsearch;

The Set/get method automatically generated with myeclipse 6.0 is
The corresponding set/get method is

 

Public Boolean ishighsearch (){
Return ishighsearch;
}

Public void sethighsearch (Boolean ishighsearch ){
This. ishighsearch = ishighsearch;
}

 

Then in the action

Searchinfobean = new searchinfobean ();
System. Out. println (searchinfobean. ishighsearch ());

The printed value is always false, which is inconsistent with the form value.

Later, we found that the get method automatically generated by myelipse, which belongs to the boolean type, is automatically prefixed with "is" in the attribute name ",
The above example is ishighsearch,

 

The solution is to change the attribute name to highsearch, remove the preceding is, and then obtain the value of highsearch correctly.

Modify the JSP page

<Input id = "searchinfo. highsearch" name = "searchinfo. highsearch" value = "true" type = "hidden"/>

 

Change the Bean class attribute

Private Boolean highsearch;

 

Public Boolean ishighsearch (){
Return highsearch;
}

Public void sethighsearch (Boolean highsearch ){
This. highsearch = highsearch;
}

 

To sum up, the attribute name of the JavaBean object. If it is a Boolean attribute, it cannot start with "is". This will avoid unnecessary issues.

Error

Related Article

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.