Description of the Request Parameter url of struts2 and the integration of struts2 and Spring

Source: Internet
Author: User

Description of the Request Parameter url of struts2 and the integration of struts2 and Spring

When using struts2, we all know that the previous discrete value is used as the transmission unit. Their request url is written as follows: localhost: 8080/test/login? Username = hello & password = world

And the corresponding action is written in this way.

Public class LoginAction extends ActionSupport {private String username; private String password; // the corresponding getter setter method is omitted below .... @ Overridepublic String execute () throws Exception {//.......... some business logic code return SUCCESS ;}}

 

 

Public class LoginAction extends ActionSupport {private User user User; // the corresponding getter setter method is omitted below .... @ Overridepublic String execute () throws Exception {//.......... some business logic code return SUCCESS ;}}
If struts2 is written in this way, a User object can be automatically generated, and the property value in the User object is the value from the url of the request parameter.

 

Localhost: 8080/test/login? User. username = hello & user. password = world (user. username = hello & user. password = world)

 

It is worth noting that if the property in the corresponding User object does not have the corresponding parameter to copy to him, it is null.

If the url value of the request parameter is greater, for example, http: // localhost: 8080/test/login? User. username = hello & user. password = world & user. permission = 1, the following exception is thrown:

Ognl. NoSuchPropertyException: com. test. entity. User. permission

 

 

 

 

**************************************** **************************************** * ************* This is a split line

By the way, if Spring integrates struts2, the action can be driven by Spring annotation .... The statement is as follows:

 

@Controller(login)@Scope(prototype)public class LoginAction extends ActionSupport{private User user;public User getUser(){return user;}public void setUser(User user){this.user = user;}@Overridepublic String execute() throws Exception{System.out.println(this.user.getUsername());System.out.println(this.user.getPassword());System.out.print(user object is null ? answer is );System.out.println(this.user == null);return SUCCESS ;}}

You can use the @ Controller (login) annotation for the driver. @ Scope (prototype) indicates that this action is a singleton.

 

The login in @ Controller indicates the class attribute in the struts. xml configuration file.

 

Do you think of The struts2 type converter! However, I personally think that the struts2 type converter still needs to exist, because the url request format generated during form submission is the previous one, that is, localhost: 8080/test/login? Username = hello & password = world

 

Of course, if you use javascript scripts to convert the url request format generated by them to the following format, it is also possible.

Localhost: 8080/test/login? User. username = hello & user. password = world

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.