I’ve got a simple http POST action in Spring MVC and I don’t need to return a full web page. Instead I just need to return an xml string (for example)
true
But when I exec the action below my client is getting a 404
@RequestMapping(value = "/updateStuffAjaxStyle.do", method = RequestMethod.POST)
public String updateStuffAjaxStyle(HttpServletRequest request, HttpServletResponse response) {
//..do something w/ the inputs ...
return "<valid>true</valid>";
}
Is it possible to return a simple xml string like this w/out having to define a ton of bean defs?
Yes, it is. But not by returning the String from your method, but by writing it to the
HttpServletResponse.getWriter()and changing the method signature to returnvoid(this way, Spring will know that you’ll handle the response yourself).To grab the servlet response writer, simply add one extra argument of type
java.io.Writerto your method, and Spring will provide you with the proper reference.