简介:
有时候需要重定向到别的项目去,又不想更改前端,可以试试这个方法
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @PostMapping("/redirectUrl") public void redirectUrl(HttpServletRequest request, HttpServletResponse response) throws IOException { String redirectUrl = "www.baidu.com"; response.setHeader("Content-Type", "text/html; charset=UTF-8"); response.getWriter().write("<script>window.location.replace(\'" + redirectUrl + "\')</script>"); response.getWriter().flush(); response.getWriter().close(); }