Reputation: 47
I have written a simple code to integrate REST with Struts 2.3.24.
I have my Struts XML:
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.mapper.class" value="rest" />
<!-- Overwrite Convention -->
<constant name="struts.convention.action.suffix" value="Controller"/>
<constant name="struts.convention.action.mapAllMatches" value="true"/>
<constant name="struts.convention.default.parent.package" value="com.pag.rest.service"/>
<constant name="struts.convention.package.locators" value="service"/>
</struts>
And my controller class is:
package com.pag.rest.service;
public class RequestController {
// GET
public String index() {
return "SUCCESS";
}
// GET
public String show() {
return "SUCCESS";
}
// POST
public String create() {
return "Create - SUCCESS";
}
// PUT
public String update() {
return "SUCCESS";
}
// DELETE
public String destroy() {
return "SUCCESS";
}
}
Whenever I try to access the service, it says not found with action not mapped
exception.
Please, let me know, what else I need to do in order to get the code working?
Upvotes: 4
Views: 436
Reputation: 1
The parent package should be rest-default
. Add the following constant to the configuration file struts.xml
:
<constant name="struts.convention.default.parent.package" value="rest-default"/>
Remove
<constant name="struts.convention.package.locators" value="service"/>
And rename your package name to com.pag.rest.actions
. It will search your controllers under the actions
folder.
Upvotes: 0