javaweb实例--网页的自动刷新功能实现

javaweb实例–网页的自动刷新功能实现

做个记录啊,如果看不懂可以留言,我就不详细的写博客了

创建一个RefreshServelet.java

package cn.kuls.demo1;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "RefreshServlet",urlPatterns = "/refresh")
public class RefreshServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       String message="3秒后自动跳转首页,如果没有跳转请点击跳转链接";

        request.setAttribute("message",message);
        request.getRequestDispatcher("/index.jsp").forward(request,response);
    }
//这里大家可以忽略
    private void Refresh(HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=utf-8");
        response.setHeader("refresh","3;url='/hello/sign.html' ");
        response.getWriter().print("3s后自动跳转");
    }
}

然后自然就是写下跳转到的界面

简单粗暴!

你可能感兴趣的:(javaweb)