UrlRewriteFilter规则删除JSP文件扩展名 [英] UrlRewriteFilter Rule to Remove JSP File Extention
问题描述
我想使用UrlRewriteFilter以通用方式删除JSP文件扩展名,以避免必须为150多个文件指定单独的servlet映射.有人知道这样的规则是什么吗?
I would like to use UrlRewriteFilter to remove JSP file extentions in a generic manner to avoid having to specify individual servlet-mappings for 150+ files. Does anyone know what the rule would be for something like that?
从* .jsp到*
即:/Login.jsp将被翻译为/Login
ie: /Login.jsp would be translated to /Login
推荐答案
因此,经过大量实验,我发现了如何使用urlrewrite从所有页面中删除JSP扩展名.以下规则转换页面URI中包含1个或多个字符的任何页面,并将其转发到[页面名称] .jsp
So after much experimentation I found out how to do remove the JSP extension from all pages with urlrewrite. The rule below translates any page that has 1 or more characters in the page URI and forwards it to [page name].jsp
重要的是,如果规则不在我的站点的上下文根目录之外而不是JSP页面,则不要触发该规则,因此我要排除文件夹css,img,css,product-img中的文件
Its important to not fire the rule if its not a JSP page off the context root for my site so I exclude files in folders css, img, css, product-img
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite
PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
"http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">
<urlrewrite>
<rule match-type="regex">
<condition type="request-url" operator="notequal">^.*\.jsp$</condition>
<condition type="request-url" operator="notequal">/css/.*</condition>
<condition type="request-url" operator="notequal">/img/.*</condition>
<condition type="request-url" operator="notequal">/js/.*</condition>
<condition type="request-url" operator="notequal">/product-img/.*</condition>
<from>/.+(?:(?!jsp).).$</from>
<to type="forward">%{request-uri}.jsp</to>
</rule>
</urlrewrite>
可以在Tuckey的maven网站上找到jar文件,网址为 https://mvnrepository .com/artifact/org.tuckey/urlrewritefilter/4.0.3 (下载链接在主页上断开)
The jar file can be found on tuckey's maven site here https://mvnrepository.com/artifact/org.tuckey/urlrewritefilter/4.0.3 (download link is broken on the main page)
这是他的主要网站 urlrewrite主要网站
这篇关于UrlRewriteFilter规则删除JSP文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!