我有一个struts2应用程序,它使用struts2-rest-plugin v.2.2.3.
当涉及到请求到动作及其方法的路由时,一切都很好.我还使用ModelDriven来指定在使用JSON和XML等扩展时要序列化的对象.
我遇到的问题是,当我向struts层发送POST或PUT请求时,我得到一个空响应.
我正在向动作发送POST请求,如下所示:http://localhost:8080/alert-settings!update.json.我在该方法中有一个断点,它被调用,代码运行并完成.我有一种感觉,问题可能是我试图使用ModelDriven接口向我发回响应,并且由于某种原因,rest-plugin不喜欢这个,但我不知道它为什么会这样.
在使用rest插件时,是否存在从POST请求接收响应的已知问题?我到处都看,真的找不到任何关于它的东西.
任何帮助表示感谢,我可以根据要求提供更多详细信息.
我写了一个简单的代码来将rest与Struts 2.3.24集成
我有我的 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>
Run Code Online (Sandbox Code Playgroud)
我的控制器类是:
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 …Run Code Online (Sandbox Code Playgroud)