Spring 3 MVC:整个站点的相同 URL
我试图让用户看到相同的静态 URL,尽管他们所在的页面会发生变化。
例如,我希望用户始终看到:
www.mysite.com
即使我将他们重定向到
www.mysite.com/1.html
www.mysite.com/2.html
- < code>www.mysite.com/2.jsp
等等...
我有 Spring MVC,它隐藏了 JSP,但我想要一个“静态隐藏 URL”。谁能告诉我如何实现它?
I'm trying to make it so that users will see the same static URL although page they are on will change.
For example, I want the user to always see:
www.mysite.com
Even if i redirect them to
www.mysite.com/1.html
www.mysite.com/2.html
www.mysite.com/2.jsp
etc...
I have Spring MVC, and that hides the JSP, but I want a "static hide URL". Can anybody tell me how to achieve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将控制器映射到“/”并设置 ViewResolvers 来处理每个视图。然后控制器需要通过返回不同的视图名称将请求定向到适当的视图。
请注意,如果不提供替代 URL,您将需要求助于 Cookie、POST 请求或其他逻辑来确定要呈现的页面/视图,这会让生活变得有点困难。
认真考虑一下您是否真的需要 HTTP 请求级别的一个 URL。如果您只想让浏览器地址栏保持不变,那么 Frames 或 AJAX 可能是一种更简单的方法,在幕后,它们允许使用不同的 URL,而无需更改浏览器窗口顶部的地址。
Map the Controller to "/" and set up ViewResolvers to handle each view. The controller then needs to direct the request to the appropriate view, by returinign different view names.
Note, that without offering alternative URLs you will need to resort to Cookies, POST requests or other logic to determine which page / view to render, which makes life a little harder.
Think seriously about whether you really want one URL at the HTTP request level. If all you want is to make the browser address bar stay the same them Frames or AJAX may be an easier way forward, behind the scenes these allow for different URLs to be used without changing the address at the top of the browser window.