package cn.itcast.response;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//控制浏览器定时刷新
public class ResponseDemo5 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
test3(request, response);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//实用的自动跳转
public void test3(HttpServletRequest request,HttpServletResponse response) throws IOException, Exception {
String message = "<meta http-equiv='refresh' content='3;url=/day06/message.jsp'>恭喜你,登陆成功本浏览器将在3s后跳到首页,如果没有跳转,请点击<a href=''>超链接</a>";
this.getServletContext().setAttribute("message", message);
this.getServletContext().getRequestDispatcher("/message.jsp").forward(request, response);
}
public void test2(HttpServletResponse response) throws IOException {
//假设这是一个用于处理登陆的servlet
//假设运行到此用户登陆成功了
response.setHeader("refresh","3;url='/day06/index.jsp'");
response.setContentType("text/html;charset=UTF-8");
response.getWriter().write("恭喜你,登陆成功本浏览器将在3s后跳到首页,如果没有跳转,请点击<a href=''>超链接</a>");
}
public void test1(HttpServletResponse response) throws IOException {
response.setHeader("refresh", "3");
String data = new Random().nextInt(1000000)+"";
response.getWriter().write(data);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
}
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//控制浏览器定时刷新
public class ResponseDemo5 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
test3(request, response);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//实用的自动跳转
public void test3(HttpServletRequest request,HttpServletResponse response) throws IOException, Exception {
String message = "<meta http-equiv='refresh' content='3;url=/day06/message.jsp'>恭喜你,登陆成功本浏览器将在3s后跳到首页,如果没有跳转,请点击<a href=''>超链接</a>";
this.getServletContext().setAttribute("message", message);
this.getServletContext().getRequestDispatcher("/message.jsp").forward(request, response);
}
public void test2(HttpServletResponse response) throws IOException {
//假设这是一个用于处理登陆的servlet
//假设运行到此用户登陆成功了
response.setHeader("refresh","3;url='/day06/index.jsp'");
response.setContentType("text/html;charset=UTF-8");
response.getWriter().write("恭喜你,登陆成功本浏览器将在3s后跳到首页,如果没有跳转,请点击<a href=''>超链接</a>");
}
public void test1(HttpServletResponse response) throws IOException {
response.setHeader("refresh", "3");
String data = new Random().nextInt(1000000)+"";
response.getWriter().write(data);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
}