Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

The example code for this tutorial, annotations, is available for checkout at https://svngithub.apache.org/repos/asf/struts/sandbox/trunk/struts2examples/com/apache/struts-examples

Introduction

In our previous tutorials we've been using an XML file (struts.xml) to configure our applications. The XML file wires up the action names (register), with ActionSupport classes (RegisterAction.java), and with the result to render back to the browser (register.jsp). Struts 2 provides an alternative to using XML to configure your application by using standard naming conventions and annotations for your action names, ActionSupport classes, and results.

...

Code Block
xml
titleConvention Plugin Dependency
xml


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

...

Code Block
java
titleAction Annotation
java


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

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

...

Code Block
xml
titlestruts.xml parameter configuration
xml


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

...

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>

...