web访问路径url省略jsp等后缀--伪静态

下载urlrewritefilter-4.0.3.jar添加到项目中

在WEB-INF中新建urlrewrite.xml文件



<urlrewrite>
    <rule>
        <from>^/index$from>  
        <to type="forward">/index.jspto> 
    rule>
    <rule>
        <from>^/login$from>  
        <to type="forward">/login.jspto> 
    rule>
    <rule>
        <from>^/register$from>  
        <to type="forward">/register.jspto> 
    rule>
    <rule>
        <from>/useraction/myprofile.htmlfrom>
        <to type="forward">/useraction/myprofile.doto>
    rule>
urlrewrite>

在web.xml中最上面添加配置:

      
      <filter>
        <filter-name>UrlRewriteFilterfilter-name>
        <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilterfilter-class>
        
        <init-param>
            <param-name>confReloadCheckIntervalparam-name>
            <param-value>60param-value>
        init-param>

        
        <init-param>
            <param-name>confPathparam-name>

             <param-value>/WEB-INF/urlrewrite.xmlparam-value>
        init-param>

        
        <init-param>
            <param-name>logLevelparam-name>
            <param-value>DEBUGparam-value>
        init-param>
    filter>

    <filter-mapping>
        <filter-name>UrlRewriteFilterfilter-name>
        <url-pattern>/*url-pattern>
        <dispatcher>REQUESTdispatcher>
        <dispatcher>FORWARDdispatcher>
    filter-mapping>

然后访问http://127.0.0.1:8080/springtest/login正确跳转至登录页面

你可能感兴趣的:(web)