Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
92 views
in Technique[技术] by (71.8m points)

java - Does spring mvc have response.write to output to the browser directly?

I am using spring mvc with freetemplate.

In asp.net, you can write straight to the browser using Response.Write("hello, world");

Can you do this in spring mvc?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can either:

  • get the HttpServletResponse and print to its Writer or OutputStream (depending on whether you want to send textual or binary data)

    @RequestMapping(value = "/something")
    public void helloWorld(HttpServletResponse response)  {
      response.getWriter().println("Hello World")
    }
    
  • Use @ResponseBody:

    @RequestMapping(value = "/something")
    @ResponseBody
    public String helloWorld()  {
      return "Hello World";
    }
    

Thus your Hello World text will be written to the response stream.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...