【问题标题】:Issues with creating REST rules with UrlRewriteFilter使用 UrlRewriteFilter 创建 REST 规则的问题
【发布时间】:2014-08-14 03:34:16
【问题描述】:

我设置了我的 tomcat 服务器以使用 urlRewriterFilter 来启用 AngularJS 中的 html5 功能并从 url 中删除 #。似乎 urlRewriterFilter 可以正常处理以下格式的请求: <SERVER>/<APP_NAME>/tracks - 页面加载正常。

问题: 是这样的请求: <SERVER>/<APP_NAME>/tracks/<TRACK_NAME>/<TRACK_ID>。 - 加载 index.html 好的,但资源不是。

所以我得到 404,因为路径错误

<SERVER>/<APP_NAME>/tracks/<TRCK_NAME>/bower_components/underscore/underscore.js 

代替:

<SERVER>/<APP_NAME>/bower_components/underscore/underscore.js 

问题: 如何告诉 UrlRewriterFilter 在匹配规则后不要连接 url? 我是否以错误的方式在 index.html 中添加了库?

urlrewrite.xml

<urlrewrite default-match-type="wildcard">
    <!-- All requests to root are forwarded to home page. -->

    <rule>
        <from>/signup</from>
        <to>index.html</to>
    </rule>

    <rule>
        <from>/tracks</from>
        <to>index.html</to>
    </rule>

    <rule>
        <from>/tracks/**</from>
        <to>/index.html</to>
    </rule>

</urlrewrite>

Chrom 开发控制台

GET http://localhost:8080/devstage-1.0/tracks/analysis/bower_components/moment/moment.js 404 (Not Found) 

它尝试从http://localhost:8080/devstage-1.0/tracks/analysis而不是http://localhost:8080/devstage-1.0/加载时刻

UrlRewriteFilter 日志: (sn-p)

DEBUG|http-apr-8080-exec-2|o.s.s.web.FilterChainProxy    | /tracks/analysis/bower_components/moment/moment.js at position 1 of 12 in additional filter chain; firing Filte
r: 'CORSFilter'
DEBUG|http-apr-8080-exec-10|o.s.s.web.FilterChainProxy    | /tracks/analysis/bower_components/angular-route/angular-route.js at position 3 of 12 in additional filter chai
n; firing Filter: 'SecurityContextPersistenceFilter'
DEBUG|http-apr-8080-exec-8|o.s.s.web.FilterChainProxy    | /tracks/analysis/bower_components/angularytics/dist/angularytics.js at position 1 of 12 in additional filter ch
ain; firing Filter: 'CORSFilter'
DEBUG|http-apr-8080-exec-2|o.s.s.web.FilterChainProxy    | /tracks/analysis/bower_components/moment/moment.js at position 2 of 12 in additional filter chain; firing Filte
r: 'WebAsyncManagerIntegrationFilter'

我像这样在 index.html 中加载资源:

<script src="bower_components/jquery/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/underscore/underscore.js"></script>

【问题讨论】:

    标签: html spring angularjs url-rewriting tuckey-urlrewrite-filter


    【解决方案1】:

    它源于我计算base URL 的方式存在错误。一旦它被添加到head 的第一行,资源就可以正常加载。

    <base href='http://localhost:8080/<MY_APP_NAME>/'/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-24
      • 2012-08-04
      • 1970-01-01
      • 1970-01-01
      • 2011-04-10
      相关资源
      最近更新 更多