Struts2 page URL request how to find action

Source: Internet
Author: User

1. We use the most primitive method to find the action. different annotations.

Struts.xml files are configured first

<!--Press Info action---
<action name= "newsinfoaction" class= "Com.xxx.NewsInfoAction" >
<result name= "Add" >news/addNewsInfo.jsp</result>
<result name= "Update" >news/editNewsInfo.jsp</result>
<result name= "DataList" >news/newsInfo.jsp</result>
</action>

Action defaults to running the Excute method in Newsinfoaction.

Http://localhost:8080/test/newsInfoAction.html or Http://localhost:8080/test/newsInfoAction.action See how you configure in the Struts.xml file (

<!--change suffix--
<constant name= "struts.action.extension" value= "action,html"/>)

So there is a question, how do we access the other methods in Newsinfoaction?

Access to the specified method

Way One:

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

Ability to invoke the Say method in the action of Hello

Way two:

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

Ability to invoke the Say method. Here, the name of the parameter is: Method:say, this is the most basic, struts2 exactly

Depending on the name of the parameter to determine which method to call, not the value of the parameter, so the value of the parameter can be arbitrary

Way three:

A method attribute exists in the action tag of the STRUTS2 configuration file to specify the access specific methods

<action name= "Hello" class= "helloaction" method= "Say" >

Mode four:

<action name= "hello_*" class= "helloaction" method= "{1}" >

This way the action path in the page can be written as hello_say.action is the Say method.



2. Assume that Struts2 has been handed over to the spring container management. We can use annotations to find action and the action's method.

(It is recommended to use this method.) So we don't have to configure all kinds of action in Struts.xml file, can give Struts.xml lose weight.

URL: http://localhost:8080/test/admin/editproduct.html?productInfoId=1//Number of parameters is optional

@SuppressWarnings ("Unchecked")
@Action (value = "/admin/editproduct", results = {@Result (name = "Update", location = "product/editproductinfo.jsp")})
Public String Toupdateproductinfo () throws Exception {

。。。。。

}

Configuration files require only configuration annotations to:

<mvc:annotation-driven/>
<context:annotation-config></context:annotation-config> cannot be shortened into <context:annota Tion-config/>






Struts2 page URL request how to find action

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.