gpt4 book ai didi

java - 在 Spring 中返回一个没有重定向的静态 html

转载 作者:搜寻专家 更新时间:2023-10-31 08:14:59 25 4
gpt4 key购买 nike

所以我想返回一个 HTML 页面而不发送重定向。原因是使用重定向会更改浏览器中的 URL,如果他们未登录,我无法将他们重定向到登录。最直接的方法是什么?似乎不使用 jsp 或其他服务器端 View 技术应该很简单。

最佳答案

你可以使用forward

例子:

/static/myWebpage.html 是你的静态 html 页面

此代码将返回 myWebpage.html 的内容而不更改 url

@Controller
@RequestMapping("/path")
public class TestingController {
@RequestMapping("/page")
public String someOtherPage(HttpServletRequest request, HttpServletResponse response) {
return "forward:/static/myWebpage.html";
}
}

同样,您的 url 将是“localhost/path/page”,但您将查看“localhost/static/myWebPage.html”

关于java - 在 Spring 中返回一个没有重定向的静态 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24071220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com