开发者

Dummy View with Spring MVC

I have the following piece of code in my Spring MVC application:

@RequestMapping(value = "/ping")
public void ping () {

}

I want to respond to that request with a simple pla开发者_如何转开发in text with:

OK!

But I'm currently using a ResourceBundleViewResolver, having my jsp's in the WEB-INF/views folder... Is there a way to output plain text only by modifying the content of my ping () method? Thanks!


Another posibility:

@RequestMapping(value = "/ping")
public void ping (HttpServletResponse response) {
PrintWriter out;
response.setContentType("text/plain");
try {
out = response.getWriter();
out.write(message);
}
catch (IOException ex) {
     ex.printStackTrace();

} finally {
  out.close();
}
}

If you need to return text, use what @skaffman suggested it's better aproach, if you need to return file or any other object with different content type (file or file chunk, for example) you can use this approach.


Try this:

@RequestMapping(value = "/ping")
@ResponseBody
public String ping () {
   return "OK!";
}


Use the mvc namespace. Something like Viewname = jspfile

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜