//重定向
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// //1.设置状态码
// response.setStatus(302);
// //2.设置响应头location
// response.setHeader("Location", "/web01/servlet03");
//开发中专门重定向方法
response.sendRedirect("/web01/servlet03");
//设置状态码
response.setStatus(404);
response.getWriter().write("hello hello...");
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//定时刷新(5秒后跳转)
response.setHeader("refresh", "5;url=http://www.baidu.com");
response.getWriter().write("hello dandan...");
}
jsp文件
<title>Insert title here</title>
<script type="text/javascript">
var time =5;
//全局加载完再执行
window.onload =function(){
var second =document.getElementById("second");
timer =setInterval(function(){
second.innerHTML =time;
time--;
if(time==0){
clearInterval(timer);
location.href="http://www.baidu.com";
}
}, 1000);
}
</script>
</head>
<body>
恭喜注册成功!<span style="color:red " id="second">5</span>秒后跳转
如果不跳,请点击<a href="http://www.baidu.com">百度</a>
</body>
</html>
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// //设置缓冲区的编码
// response.setCharacterEncoding("utf-8");
// //告知客户端用utf-8解码
// response.setHeader("Content-Type", "text/html;charset=utf-8");
//开发中专门解码方法
response.setContentType("text/html;charset=utf-8");
response.getWriter().write("中国");