我是struts的新手。我正在使用struts2 rest编写一个Web应用程序。我有struts2配置为接受休息和非休息网址。 (关注http://struts.apache.org/release/2.3.x/docs/rest-plugin.html)
我希望" http://mylocalhost.com/myApp/detail" url调用DetailController类的index()方法。但是,我收到了这个错误:
java.lang.NoSuchMethodException: com.project.struts.rest.controllers.DetailController.execute()
java.lang.Class.getMethod(Class.java:1665)
似乎struts解决了它需要调用detailController,但它尝试调用execute()方法而不是index()方法。
我的struts配置中遗漏了什么吗?
struts.xml configure file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.action.extension" value="xhtml,,xml,json,action"/>
<constant name="struts.mapper.class" value="org.apache.struts2.dispatcher.mapper.PrefixBasedActionMapper" />
<constant name="struts.mapper.prefixMapping" value="/rest:rest,:struts"/>
<constant name="struts.convention.action.suffix" value="Controller"/>
<constant name="struts.convention.action.mapAllMatches" value="true"/>
<constant name="struts.convention.default.parent.package" value="rest-default"/>
<constant name="struts.convention.package.locators" value="controllers"/>
</struts>
我在com.project.struts.rest.controllers
中有一个名为DetailController的控制器DetailController类: 包com.project.struts.rest.controllers;
import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;
import com.opensymphony.xwork2.ModelDriven;
public class DetailController implements ModelDriven<Object> {
private String propertyId;
@Override
public Object getModel() {
// TODO Auto-generated method stub
return null;
}
// GET /test/1
public HttpHeaders show() {
return new DefaultHttpHeaders("show");
}
// GET /test
public HttpHeaders index() {
return new DefaultHttpHeaders("index");
}
}