STRUTS2 Convention Plug-in 0 configuration, using annotation development

Source: Internet
Author: User

Starting with STRUTS21, struts2 no longer recommends using Codebehind as a 0 configuration plug-in, but instead uses convention plug-ins to support 0 configurations. The Convention plugin is more thorough than before.

With the Convention plug-in, you need to copy the Struts2-convention-plugin-2.3.1.2.jar file to the Lib directory

This plugin is a feature that automatically searches for action:

  The rules are as follows: It automatically searches for Java classes that are located under the Action,actions,struts, STRUTS2 package.

The Convention plugin will treat the following two Java classes as action:

1. All Java classes that implement the Com.opensymphony.xwork2.Action

2. All Java classes with a class name ending with action

Once the corresponding action class is found, the Convention plug-in deploys these actions as agreed, and when the action is deployed, the ACTION,ACTIONS,STRUTS,STRUTS2 package is mapped to the root namespace, and the

The child package is mapped to the corresponding namespace.

The annotation function of this plugin

  Sometimes for struts2 application, we write a lot of XML configuration, this find action, and then find configuration, very inconvenient, combined with annotations open, open the corresponding action can let people at a glance

Online has a lot of predecessors to write a lot of summary, I directly apply on it, haha

Reference:

http://blog.csdn.net/oathevil/article/details/7084979

   Convention Plug-in official learning document

  

  The test code from a

   

 PackageCom.hu.web.action;//Be sure to take action, actions, struts, struts2 this package, or the plugin cannot scan this actionImportorg.apache.struts2.convention.annotation.Action;Importorg.apache.struts2.convention.annotation.Actions;ImportOrg.apache.struts2.convention.annotation.Namespace;ImportOrg.apache.struts2.convention.annotation.Result;ImportOrg.apache.struts2.convention.annotation.ResultPath;ImportCom.opensymphony.xwork2.ActionSupport; @Namespace ("/test")//Accessing the test space@ResultPath ("/web-inf")//specify the action to look for the physical view resource under the/web-inf directory Public classLoginactionextendsActionsupport {PrivateString name; PrivateString pwd; PrivateString tip;  PublicString GetName () {returnname; }     Public voidsetName (String name) { This. Name =name; }     PublicString getpwd () {returnpwd; }     Public voidsetpwd (String pwd) { This. PWD =pwd; }                 PublicString Gettip () {returntip; }     Public voidSettip (String tip) { This. tip =tip; } @Actions ({@Action (value= "/test", results={@Result (name= "Login", location= "/index.jsp")}), @Action (value= "/test1", params={"Tip", "when accessing this action path is, the Tip attribute value will be injected"})    })     PublicString Login () {System.out.println (1); return"Login"; }}

Software that makes life easier ...

STRUTS2 Convention Plug-in 0 configuration, using annotation development

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.