spring mvc有response.write直接输出到浏览器吗? [英] Does spring mvc have response.write to output to the browser directly?
本文介绍了spring mvc有response.write直接输出到浏览器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用带有freetemplate的spring mvc。
I am using spring mvc with freetemplate.
在asp.net中,你可以使用Response.Write直接写入浏览器(hello,world);
In asp.net, you can write straight to the browser using Response.Write("hello, world");
你能在春天的mvc做这个吗?
Can you do this in spring mvc?
推荐答案
你可以要么:
-
获取
HttpServletResponse
并打印到其Writer
或OutputStream
(取决于您是否要发送文本或二进制数据)
get the
HttpServletResponse
and print to itsWriter
orOutputStream
(depending on whether you want to send textual or binary data)
@RequestMapping(value = "/something")
public void helloWorld(HttpServletResponse response) {
response.getWriter().println("Hello World")
}
使用 @ResponseBody
:
@RequestMapping(value = "/something")
@ResponseBody
public String helloWorld() {
return "Hello World";
}
因此你的 Hello World
文本将被写入响应流。
Thus your Hello World
text will be written to the response stream.
这篇关于spring mvc有response.write直接输出到浏览器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文