Reputation: 1
BufferedHttpServletResponse bufferedHttpServletResponse = new BufferedHttpServletResponse(response);
request.getRequestDispatcher(jspPage).forward(request, bufferedHttpServletResponse);
String xmlData = bufferedHttpServletResponse.getData();
This is what i am using along with modelAndView
my anyChart
component require data in XML file,this file should be generated dynamically but it says response is already committed.
Upvotes: 0
Views: 462
Reputation: 3908
You could use a Servlet
and directly print out the answer:
public void service(ServletRequest request, ServletResponse response){
response.setContentType("text/xml;charset=UTF-8");
PrintWriter writer = response.getWriter();
writer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
writer.append("<result>");
// print your result
writer.append("</result>");
It's not from within a JSP, but it almost looks like you are already inside a Servlet
.
If you are using Spring Web MVC, what your referral to modelAndView suggests, you might just want to use a method in your controller with @ResponseBody
annotation on the return type.
@RequestMapping(value = "/xmlresponse", method = RequestMethod.GET)
public @ResponseBody ResultObjectWithJaxbAnnotations gernerateXmlResult() {
Don't forget <mvc:annotation-driven />
in your Spring application-context - but you will have that most likely already.
Upvotes: 2