Matching between action and action in Java Web (Business Controller) (1)

Source: Internet
Author: User

For beginners, the question of how struts connects action and action classes has been plagued by many people. Here I will explain to you:

Assuming that the attributes in JSP are fixed and tentatively set to name, how can we define the attribute in the action class implemented by JSP to be valid?

A. The setname (string) method must be available;

B. The getname () method must exist;

What about the parameter? What about object attributes?

The answer is: no matter what the name is.

Still do not understand ??? Let's take the following example:

 

(1) code in the JSP file <s: Form Action = "registpro"> <s: textfield name = "name" label = "username"/> <tr> <TD colspan = "2"> <s: submit value = "register" theme = "simple"/> <s: reset value = "Refill" theme = "simple"/> </TD> </tr> </S: Form> (2) code Form 1 of the action class: public class registaction {private string name; // setter and getter methods of the name attribute public void setname (string name_hah) {This. name = name_hah;} Public String getname () {return this. name ;}// other processing functions using name} Form 2: Public class registaction {private string name_hah; // setter and getter methods of the name attribute public void setname (string name) {This. name_hah = Name;} Public String getname () {return this. name_hah;} // other handler functions using name. So what is a problem? In this case: public class registaction {private string name; // setter and getter methods of the name attribute public void setname_hah (string name) {This. name = Name;} Public String getname () {return this. name;} // other processing functions using name}

 

Because the system cannot find the setname (string) method, an error is reported.

 

Now you should understand it, right ??? What ??? Still do not understand.

Okay, you are not saved.

 

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.