//请求转发
<% request.getRequestDispatcher("/WEB-INF/pages/index.jsp").forward(request, response); %>
//重定向
res.sendRedirect(req.getContextPath() + "/login.html"); return;
//response
res.setCharacterEncoding("utf-8"); res.setContentType("text/html;charset=UTF-8"); OutputStream out = res.getOutputStream(); PrintWriter pw = new PrintWriter(new OutputStreamWriter(out,"utf-8")); pw.println("{\"result\":false,\"errorMessage\":\"http session is timeout,please login again\"}"); pw.flush(); pw.close();
response.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); PrintWriter pw = null; try { pw = response.getWriter(); } catch (IOException e) { e.printStackTrace(); } finally { if(pw != null) { pw.print("{\"result\":false,\"errorMessage\":\"http session is timeout,please login again\"}"); pw.close(); } }
//html自动跳转
<html> <head> <meta http-equiv="refresh" content="0;url="http://www.baidu.com"> <!--0是等待时间,如果设置为5表示等待5s后开始跳转 --> </head>
//js
window.location.replace("http://www.baidu.com"); //无历史记录 window.location="url"; //有历史记录 self.location='top.htm'; top.location='xx.jsp'; <a href="javascript:history.go(-1)">返回上一步</a> <a href="javascript:history.back()">返回上一步</a>