路径定向错误
来源:互联网 发布:高中数学最优化问题 编辑:程序博客网 时间:2024/06/06 01:51
在使用springmvc框架时,出现路径定向错误
因为将default servlet映射至/static/的子目录,现我们访问静态资源将会带一个/static/前缀;
而在有些电脑上,又没有加上static前缀;
或者在web.xml 中 增加
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>
解决办法:使用 静态资源的URL重写
参照网址:http://www.congci.com/item/spring,mvc,restful,url
添加:
urlrewrite-2.6.0.jar-> WebRoot/WEB-INF/lib/urlrewrite-2.6.0.jar
添加:
urlrewrite.xml -> WebRoot/WEB-INF/urlrewrite.xml
urlrewrite.xml中的内容如下:
<urlrewrite>
<!-- 访问jsp,jspx,jpg,gif,css将不rewriteurl,其它.js,.css,.gif等将重写,如 /foo.gif=> /static/foo.gif asf-->
<rule>
<conditionoperator="notequal"next="and"type="request-uri">.*.jsp</condition>
<conditionoperator="notequal"next="and"type="request-uri">.*.jspx</condition>
<conditionoperator="notequal"next="and"type="request-uri">.*.jpg</condition>
<conditionoperator="notequal"next="and"type="request-uri">.*.gif</condition>
<conditionoperator="notequal"next="and"type="request-uri">.*.css</condition>
<from>^(/.*\..*)$</from>
<to>/static$1</to>
</rule>
</urlrewrite>
Web.xml 中加入:
<!-- urlrewrite -->
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
- 路径定向错误
- 1967 路径定向
- 【51Nod1967】路径定向
- tomcat项目路径重定向
- 转发重定向路径问题
- 51Nod-1967-路径定向
- 51nod1967 路径定向 Flenry
- haproxy重定向修改路径
- 重定向标准错误输出
- linux输出错误重定向
- 重定向标准错误输出
- 重定向标准错误输出
- Linux输入输出错误重定向
- servlet的重定向错误
- Linux输入输出错误重定向
- 使用.local 重定向DLL 加载路径
- request,路径问题,转发和重定向
- 定向输出NSLog 到沙盒路径下
- Dragon之BillingServer
- OLE Automation For Richtext Format to send mail from VFP to Lotus Notes
- struts2使用json传数据的例子
- 哎,最近忙的一塌糊涂
- leetcode Recover Binary Search Tree
- 路径定向错误
- c++模板类(一)理解编译器的编译模板过程
- NS2的UDP模拟
- 符号对象(Symbolic Object)的使用
- 划分问题(dp)
- ADO初始化接口时出现“不支持此接口”错误
- javascript对象
- java四则运算
- This project is incompatible with the current version of Visual Studio