将.do URL重定向到.action URL?

时间:2012-06-06 00:12:00

标签: struts2 struts web.xml

我在应用程序中将struts1页面迁移到struts2。但是,我仍然需要可以访问旧页面的“/login.do”URL以实现向后兼容。

如何将“login.do”网址重定向/映射为“login.action”?

我相信这可以通过编写过滤器类来实现,但我不想这样做,因为它对于任务来说似乎太复杂了。必须有一种方法可以在web.xml,struts.xml或struts-config.xml中执行此操作。

我会买一个最好回答啤酒的人(凤凰城)。 :)

1 个答案:

答案 0 :(得分:1)

更改操作扩展名。这来自default struts.properties

### Used by the DefaultActionMapper
### You may provide a comma separated list, e.g. struts.action.extension=action,jnlp,do
### The blank extension allows you to match directory listings as well as pure action names
### without interfering with static resources, which can be specified as an empty string
### prior to a comma e.g. struts.action.extension=, or struts.action.extension=x,y,z,,
struts.action.extension=action,,

首选常量的XML配置,因此我将其放在struts.xml中。

它也避免了实际的重定向,尽管这样做的过滤器很简单。