Spring-portlet POST ajax xmlHttpRequest

笑着哭i 提交于 2019-12-20 06:08:15

问题


Could please anybody who has experiences with processing post xmlHttpRequests with Spring DispatcherPortlet, tell me what is the best way to do it ? I'm using YUI io module and Jackson Object Mapper as an example :

@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 is the issue where you can vote up that spring-portlet environment will have the same support that common spring-mvc has. Which is @ResponseBody, data conversion to JSON etc. Now AFAIK one has to do it manually...

EDITED: Figured out the solution

PLEASE: Take a look at this issue which is better formulated https://stackoverflow.com/questions/4782971/handling-ajax-requests-with-spring-portlet


回答1:


How do you construct the URL? I think you're creating a Action URL, perhaps it should be an render URL. It means, instead of <portlet:actionURL/> you should be using <portlet:renderURL/>.

Hope it helps.




回答2:


I suppose the best way to respond to ajax requests in spring portlets is described in this blog post Marshal Json data using Jackson in Spring MVC with Jaxb Annotations

This also helpful Create JSON response for AJAX request in spring 3.0

Unfortunately it is not so fancy as it would be in spring-web-mvc



来源:https://stackoverflow.com/questions/4498266/spring-portlet-post-ajax-xmlhttprequest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!