多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
![](https://box.kancloud.cn/f5bdf2c89f8527b144a973067dde5ff2_559x197.png) ![](https://box.kancloud.cn/794337199c6e6baf1c00a935a7e042d2_727x319.png) 在IDEA中将一段代码抽取为方法 选择代码段右键 ![](https://box.kancloud.cn/79193cd00759e105e7b27816a076e321_1033x566.png) RefreshServlet.java ~~~ package zyw.servlet; 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/home.html'>3秒后会自动跳转到首页,如果没有跳转,请点击<a href='/hello/home.html'>跳转链接</a>"; request.setAttribute("message",message); request.getRequestDispatcher("/index.jsp").forward(request,response); } private void myrefresh(HttpServletResponse response) throws IOException { response.setContentType("text/html;charset=utf-8"); response.setHeader("refresh","3;url='/hello/home.html'"); response.getWriter().print("3秒后自动刷新"); } } ~~~ index.jsp ~~~ <%-- Created by IntelliJ IDEA. User: Administrator Date: 2018/7/7 Time: 9:04 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>JavaWeb学习</title> </head> <body> hello 你好! <%=request.getAttribute("message")%> </body> </html> ~~~ ![](https://box.kancloud.cn/5efdb8d81cc933757bff0da5f1174499_1129x179.png)