我在用着塔基网址重写 http://www.tuckey.org/urlrewrite/与 Struts2 应用程序结合使用。
我正在尝试转换以下网址:
/promotions/abcdef-987
to /dopromotions/detail
传递变量id
as 987
.
我的重写规则如下:
<rule>
<from>^/(promoties|promotions)/([0-9a-zA-Z\-_]+)-([0-9]+)$</from>
<set type="parameter" name="id">$3</set>
<to>/dopromotions/detail</to>
</rule>
我的 Struts2 Action 有以下 getter 和 setter:
private Integer id;
public void setId(Integer id){
this.id = id;
}
public Integer getId(Integer id){
return id;
}
但是,该变量永远不会被输入。调试的时候找不到id
参数或属性范围内的任何位置。
我试过删除type="parameter"
。这使得id
在属性范围内,但它没有输入我的变量中Integer id
.
我不熟悉您正在使用的 URL 重写器,但您可以单独使用 Struts2 来实现这种映射。
请参阅这个答案 https://stackoverflow.com/questions/4772737/hidden-features-of-struts-2-framework/4837917#4837917有关NamedVariablePatternMatcher
。您需要在 struts.xml 中设置以下常量:
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.patternMatcher" value="namedVariable"/>
然后,将您的操作映射为:
<!-- you could also make /promotions a namespace and the action just "abcdef-{id}" -->
<action name="promotions/abcdef-{id}" class="...">
...
</action>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)