欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

在spring mvc中使用flush先发送部分网页内容的方法,mvcflush,首先需要在spring

来源: javaer 分享于  点击 20668 次 点评:65

在spring mvc中使用flush先发送部分网页内容的方法,mvcflush,首先需要在spring


首先需要在spring mvc的请求处理方法添加response参数:

如下方法定义:

@RequestMapping(value = "/customReport", method = RequestMethod.GET)    public ModelAndView showReport(            @ModelAttribute(Constants.SESSION_KEY_LOGIN_USER) AppUser loginUser,            @RequestParam(value = "categoryId", required = false) Integer categoryId,            @RequestParam(value = "startDate", required = true) Date startDate,            @RequestParam(value = "endDate", required = true) Date endDate,            HttpServletResponse response) throws IOException { ...}

上面的方法的最后一个参数是HttpServletResponse类型的,spring mvc框架在处理请求时会自动传递response值。

在方法体中可以使用如下方法来flush部分请求:

response.setContentType("text/html;charset=utf-8");response.getWriter().write(waitingHtml);response.getWriter().flush();

上面的第一行代码设置http头,这是必须的,如果不设置会导致乱码。第二行代码写入要发送的部分内容第三行代码将部分内容发送到客户端其实质和jsp中使用是一样的。

相关栏目:

用户点评