...
As with the Codebehind Plugin, the first step is to tell the plugin where to find your resource action classes. Modify the configuration of your Struts 2 filter in web.xml
and add the 'actionPackages' init-param like so:
Code Block | ||
---|---|---|
| ||
<filter>
<filter-name>action2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value>org.apache.struts2.rest.example</param-value>
</init-param>
</filter>
| ||
Wiki Markup | ||
{snippet:url=rest-plugin/showcase/src/main/webapp/WEB-INF/web.xml|id=filter|lang=xml} |
Next, create Java objects ending in "Resource" in the configured package. The "Resource" suffix is used to distinguish Rest action resources from regular Struts 2 actions, although it is completely optional and they are functionally the same. Now, add in methods to handle the various requests. For example, the following resource action will support /orders/34
GET and PUT requests:
...