Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0
Info

The example code for this tutorial, annotations, is available for checkout at https://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2examples/Image Removed

Introduction

...

Struts 2 enables the use of standard naming conventions and annotations when you include the Convention plugin in your application's class path. If you're using Maven you'll need to add a dependency:

Code Block
xmlxml
titleConvention Plugin Dependency
xml

<dependency>
  <groupId>org.apache.struts</groupId>
  <artifactId>struts2-convention-plugin</artifactId>
  <version>2.2.1</version>
</dependency>

...

The link to Register for the drawing on the example application's home page follows this work flow. The link value is register-input.action. If you examine the RegisterAction.java class you'll find the input method with an Action annotation.

Code Block
javajava
titleAction Annotation
java

@Action("register-input")
public String input() throws Exception {

	logger.info("In input method of class Register");
		
	return INPUT;
}

...

In previous examples, we included in struts.xml values for some of the Struts 2 configuration parameters.

Code Block
xmlxml
titlestruts.xml parameter configuration
xml

<constant name="struts.devMode" value="true" />

When we don't use a struts.xml file, we can set the value of these Struts 2 parameters by using filter parameters in web.xml:

xml
Code Block
xml
titleStruts 2 Parameter Configurate web.xml
xml

<filter>
  <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
      <init-param>
	  <param-name>struts.devMode</param-name>
	  <param-value>true</param-value>
      </init-param>
</filter>

...