编程语言
首页 > 编程语言> > java 输出js实现地址跳转

java 输出js实现地址跳转

作者:互联网

简介:

        有时候需要重定向到别的项目去,又不想更改前端,可以试试这个方法

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();
}

标签:java,HttpServletResponse,javax,js,getWriter,跳转,redirectUrl,import,response
来源: https://blog.csdn.net/qq_36521848/article/details/121491102