How to find an action for a url request on the Struts2 page

Source: Internet
Author: User

1. We use the most primitive method to search for actions with different annotations.

Configure the struts. xml file first



News/addNewsInfo. jsp
News/editNewsInfo. jsp
News/newsInfo. jsp

The default action is the excute method in NewsInfoAction. Http: // localhost: 8080/test/newsInfoAction.html or http: // localhost: 8080/test/newsInfoAction. action (


)

So there is a question: how can we access other methods in NewsInfoAction?

Access the specified Method

Method 1:

Http: // localhost/struts2/simple/hello! Say. action

You can call the say method in the hello action.

Method 2:

Http: // localhost/struts2/simple/hello. action? Method: say = xxx

You can call the say method. Here, the parameter name is: method: say, which is the most important. struts2 is exactly

The method to be called is determined based on the parameter name, instead of the parameter value. Therefore, the parameter value can be any

Method 3:

There is a method attribute in the action tag of the struts2 configuration file to specify the access to a specific method.


Method 4:


In this way, the action path on the page can be written as hello_say.action, which is the way to access the say method.



2. If struts2 has been handed over to the spring container for management, we can use annotations to find the action and the action method. (This method is recommended. In this way, you do not need to configure various actions in the struts. xml file to lose weight for struts. xml .)

Url: http: // localhost: 8080/test/admin/editproduct.html? ProductInfoId = 1 // The parameter is optional

@ SuppressWarnings ("unchecked ")
@ Action (value = "/admin/editproduct", results = {@ Result (name = "update", location = "product/editProductInfo. jsp ")})
Public String toUpdateProductInfo () throws Exception {

.......

}

The configuration file only requires configuration Annotations:


Cannot be abbreviated






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.