简体   繁体   中英

Struts 1 mix url pattern *.do with regular urls web.xml

I have the following situation in a struts 1 application.

The old functionality of the application works with struts 1 and has the following servlet mapping (i think it is the standard way of doing things).

<servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
 </servlet-mapping>

I wrote some new functionality (json webservices) also in struts 1 with struts Actions.

I would like these urls to be available without the .do extension but the old url's should still work with the *.do extension.

I have tried several things like a / url pattern but this breaks the loading of static resources.

Does anyone know how to do this?

I have solved this problem in a different way. I used the tuckey url rewriter to accmplish my goal.

http://www.tuckey.org/urlrewrite/

I made the rewriter redirect

services/someService?parma1=value1&param2=value2 to severices.someService.do?parma1=value1&param2=value2

The configuration in urlrewrite.xml for this looks like this

<urlrewrite use-context="true">
    <rule>
        <from>^/services/someService$</from>
        <to last="true">/someService.do?%{QUERY_STRING}</to>
    </rule>
</urlrewrite>

The rest of the information can be found in the manual.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM