1、在spring boot中借鉴servlet的方法输出html:
@RequestMapping(value="/getPage")
public void writeSubmitHtml(Reader reader, Writer writer, HttpSession session) throws IOException {
User user = (User) session.getAttribute(ConstantConfig.LONGIN_USER);
StringBuffer sbHtml = new StringBuffer();
sbHtml.append("");
sbHtml.append("
writer.write(sbHtml.toString());
}
这里直接使用了参数 Writer writer,返回值为 void, 其实参数 Writer writer 也可以换成 PrintWriter writer; 直接写出HTML的字符流。
2.在controller中的配置:
@RequestMapping(value="/htmlView")
public void htmlView(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
// ...
request.getRequestDispatcher("index.html").forward(request, response);
//response.sendRedirect("http://www.baidu.com");
}