所以我想在不发送重定向的情况下返回HTML页面.原因是使用重定向更改了浏览器中的URL,如果他们没有登录,我无法将某人重定向到登录.有什么最直接的方法呢?看起来它应该很简单而不使用jsp或其他服务器端视图技术.
你可以用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"; } }
您的网址将是"localhost/path/page",但您将查看"localhost/static/myWebPage.html"