private void test1(HttpServletResponse response) throws IOException {
response.setHeader("refresh", "3");
String data = new Random().nextInt(100000)+"";
response.getWriter().write(data);
}
经过设置refresh头信息response.setHeader("refresh", "3;url='/day06/index.jsp'");
实现页面3秒后刷新并中转到指定url
private void test2(HttpServletResponse response) throws IOException {
response.setHeader("refresh", "3;url='/day06/index.jsp'");
response.setContentType("text/html;charset=GB2312");
String data = new Random().nextInt(100000)+"";
response.getWriter().write("登陆成功,将在3秒后跳转,若是没有,请点<a href=''>超连接</a>");
}
当页面转向message.jsp后,该页面中经过获取message中的内容并显示在浏览器中,浏览器解析出meta标签中的内容,<meta http-equiv='refresh' content='3;url=/day06/index.jsp'>从而在3秒后中转到给定的url
private void test3(HttpServletRequest request,HttpServletResponse response) throws IOException, Exception {
String message="<meta http-equiv='refresh' content='3;url=/day06/index.jsp'>登陆成功,将在3秒后跳转,若是没有,请点<a href=''>超连接</a>";
request.setAttribute("message",message);
this.getServletContext().getRequestDispatcher("/message.jsp").forward(request, response);
}