javaweb例項--網頁的自動重新整理功能實現
阿新 • • 發佈:2019-01-23
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後自動跳轉");
}
}
然後自然就是寫下跳轉到的介面
簡單粗暴!