Spring MVC 3: Returning XML through @ResponseBody

后端 未结 6 1560
渐次进展
渐次进展 2020-12-04 20:17

Pardon me for posting this noob question, but I have been debugging this problem for quite awhile now. I\'m having a little problem trying to get the response to return the

6条回答
  •  旧巷少年郎
    2020-12-04 20:51

    I solved this problem with Spring 3 mvc without MarshallingView

    @RequestMapping(value = "actionName.xml", method = RequestMethod.GET)
    public HttpEntity getXml(ModelMap map, HttpServletResponse response) {
    
        String xml = generateSomeXml();
    
        byte[] documentBody = xml.getBytes();
    
        HttpHeaders header = new HttpHeaders();
        header.setContentType(new MediaType("application", "xml"));
        header.setContentLength(documentBody.length);
        return new HttpEntity(documentBody, header);
    }
    

    that's all. greetings

提交回复
热议问题