Simplified configuration of struts2 using wildcards

Source: Internet
Author: User

Struts configuration file:

<! Doctype struts Public <br/> "-// Apache Software Foundation/DTD struts configuration 2.0/EN" <br/> "http://struts.apache.org/dtds/struts-2.0.dtd"> <br/> <struts> <br/> <package name = "sys" extends = "struts-Default" namespace = "/sys"> </P> <p> <action name = "list *" <br/> class = "org. sandbox. base. struts. SYS. {1} action "> <br/> <result name =" success "> {1} _ list. JSP </result> <br/> </Action> <br/> <action name = "prepareadd *" <br/> class = "org. sandbox. base. struts. SYS. {1} action "method =" prepareadd "> <br/> <result name =" input "> {1} _ prepareadd. JSP </result> <br/> </Action> <br/> <action name = "doadd *" <br/> class = "org. sandbox. base. struts. SYS. {1} action "method =" doadd "> <br/> <result name =" input "> {1} _ prepareadd. JSP </result> <br/> <result name = "list" type = "redirectaction"> List {1} </result> <br/> </Action> <br /> <action name = "prepareupdate *" <br/> class = "org. sandbox. base. struts. SYS. {1} action "<br/> method =" prepareupdate "> <br/> <result name =" input "> {1} _ prepareupdate. JSP </result> <br/> </Action> <br/> <action name = "doupdate *" <br/> class = "org. sandbox. base. struts. SYS. {1} action "method =" doupdate "> <br/> <result name =" input "> {1} _ prepareupdate. JSP </result> <br/> <result name = "list" type = "redirectaction"> List {1} </result> <br/> </Action> <br /> <action name = "dodelete *" <br/> class = "org. sandbox. base. struts. SYS. {1} action "method =" dodelete "> <br/> <result name =" list "type =" redirectaction "> List {1} </result> <br/> </Action> <br/> <action name = "doajaxdelete *" <br/> class = "org. sandbox. base. struts. SYS. {1} action "<br/> method =" doajaxdelete "> <br/> </Action> <br/> </package> <br/> </struts>

<Action .... class = "org. sandbox. base. struts. SYS. {1} action "...>, here {1} is the best. You can find and load the corresponding action Class Based on the actionname.

In the system, there are always some simple objects that need to provide the crud function. If you put them all in the same namespace and implement them in the same mode, the preceding configuration file is enough.

 

At the same time, this configuration, as described in the struts doc, can avoid exposing the action class method and improve security.

 

There are two minor defects:

  1. JSP file name, the original habit is that the file name is all lowercase, and the following line "_" to separate words. According to the above configuration, because the naming rules of class names are headers of uppercase letters (camelcase), the two are in conflict.
  2. From the perspective of code management requirements, the simple object management module may be distributed under multiple directories/packages. If struts supports setting the package of action class in the package definition (such as the hibernate configuration file ), you can make the preceding configuration an abstract configuration. The action class does not write the package, but only the simplename part, which further simplifies the configuration.

 

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.