UrlRewriteFilter Rule to Remove JSP File Extention

余生颓废 提交于 2019-12-10 12:01:00

问题


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?

From *.jsp to *

ie: /Login.jsp would be translated to /Login


回答1:


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

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>

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)

This is his main site urlrewrite main site



来源:https://stackoverflow.com/questions/40071157/urlrewritefilter-rule-to-remove-jsp-file-extention

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!