可以请任何有使用Spring DispatcherPortlet处理发布xmlHttpRequests的经验的人,告诉我最好的方法是什么?我使用YUI io模块和Jackson Object Mapper作为例子:
@ResourceMapping(value="stuff")
public void method(ResourceResponse response){
Person person = new Person();
person.setWeight(150);
ObjectMapper mapper = new ObjectMapper();
try{
mapper.writeValue(response.getWriter(), person);
}
...
}
的Ajax:
function() {
var A = AUI();
A.io("<portlet:resourceURL id="stuff" />", {
method: 'POST',
data: {
description: 'value'
}
});
}
This是一个问题,你可以投票决定spring-portlet环境将具有与普通spring-mvc相同的支持。哪个是@ResponseBody,数据转换为JSON等等。现在AFAIK必须手动完成...
已编辑:找出解决方案
请看一下这个问题更好的https://stackoverflow.com/questions/4782971/handling-ajax-requests-with-spring-portlet
答案 0 :(得分:0)
如何构建网址?我认为你正在创建一个Action URL,也许它应该是一个渲染URL。这意味着,您应该使用<portlet:actionURL/>
而不是<portlet:renderURL/>
。
希望它有所帮助。
答案 1 :(得分:0)
我认为在这篇博文Marshal Json data using Jackson in Spring MVC with Jaxb Annotations
中描述了响应spring portlet中的ajax请求的最佳方法。这也很有用Create JSON response for AJAX request in spring 3.0
不幸的是,它不像spring-web-mvc那样花哨