我想保留网址“http://www.mywebsite.com/hello/1111 ”,但我想显示另一个外部页面,假设我想显示 google.com。
这是我的 Controller 的代码:
@RequestMapping(value = {"hello/{id}"}, method = RequestMethod.GET)
public String helloGet(Model model, @PathVariable Integer id) {
final String url = "http://www.google.com"
return url;
}
如何在地址栏中保留“http://www.mywebsite.com/hello/1111”,并显示“www.google.com”?
最佳答案
实现此目的的一种方法是使用 iframe在您为用户生成的 View 中。
@RequestMapping(value = {"hello/{id}"}, method = RequestMethod.GET)
public String helloGet(Model model, @PathVariable Integer id) {
final String url = "http://www.google.com"
model.addAttribute("externalUrl", url);
return "hello";
}
然后在 hello.jsp 文件中可能如下所示:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<iframe src="${externalUrl}"></iframe>
</body>
</html>
另一种方法是向外部网站发出请求并将响应流式传输给用户。
关于java - 将页面重定向到另一个 url,但将 View 名称保留在地址栏中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18597280/