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

版权声明:转发者请注明地址哦-----kuls的博客-一个正在疯狂学习的大学生- https://blog.csdn.net/qq_36547531/article/details/82252276

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="<meta http-equiv='refresh' content='3;url=/hello/sign.html'>3秒后自动跳转首页,如果没有跳转请点击<a href='/hello/sign.html'>跳转链接</a>";

        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后自动跳转");
    }
}

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

简单粗暴!

猜你喜欢

转载自blog.csdn.net/qq_36547531/article/details/82252276