使Spring/Tomcat与HTML5 pushState兼容 [英] Making Spring/Tomcat compatible with HTML5 pushState
问题描述
我有一个单页Web应用程序,该Web应用程序将Backbone.js客户端路由与pushState一起使用.为了使其正常工作,我必须告诉服务器(Java,Spring 3,Tomcat)哪些URL应该在服务器上解析(实际的JSP视图,API记录),并且应该将其简单地发送到索引页面以由客户处理.当前,我正在使用InternalResourceViewResolver来简单地提供与URL请求名称匹配的JSP视图.由于客户端URL在服务器上没有视图,因此服务器返回404.
I have a single-page web app that's using Backbone.js client routing with pushState. In order to get this to work, I have to tell my server (Java, Spring 3, Tomcat) which URLs should be resolved on the server (actual JSP views, API requets), and which should simply be sent to the index page to be handled by the client. Currently I'm using an InternalResourceViewResolver to simply serve JSP views that match the name of the URL request. Since client-side URLs don't have a view on the server, the server returns a 404.
向Spring(或Tomcat)指定一些特定的URL(我的客户端路由)应该全部解析为index.jsp,而其他任何内容都应属于InternalResourceViewResolver的最佳方法是什么?
What is the best way to specify to Spring (or Tomcat) that a few specific URLs (my client-side routes) should all resolve to index.jsp, and anything else should fall through to the InternalResourceViewResolver?
推荐答案
我发现Spring MVC 3添加了一个完全符合我需要的标记,即 mvc:view-controller
标记.这为我完成了:
I found that Spring MVC 3 added a tag that does exactly what I need, the mvc:view-controller
tag. This got it done for me:
<mvc:view-controller path="/" view-name="index" />
<mvc:view-controller path="/admin" view-name="index" />
<mvc:view-controller path="/volume" view-name="index" />
http://static.springsource.org/spring/docs/3.0.x/reference/mvc.html
这篇关于使Spring/Tomcat与HTML5 pushState兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!