UrlRewrite Struts2设置参数变量 [英] UrlRewrite Struts2 setting parameter variables

查看:243
本文介绍了UrlRewrite Struts2设置参数变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Tuckey UrlRewrite 与Struts2应用程序结合使用。

I'm using Tuckey UrlRewrite in combination with a Struts2 application.

我正在尝试将以下网址:/ promotions / abcdef-987转换为/ dopromotions / detail传递变量 ID as 987

I'm trying to convert following URL: "/promotions/abcdef-987" to "/dopromotions/detail" passing variable "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:

And my Struts2 Action has following getters and setters:

private Integer id;
public void setId(Integer id){
    this.id = id;
}
public Integer getId(Integer id){
    return id;
}

但是,永远不会输入变量。在调试时,我无法在参数或属性范围内的任何位置找到id。

However, the variable never gets entered. When debugging, I can't find "id" anywhere in the parameter or attribute scope.

我尝试删除'type =参数'。这会在属性范围中添加 id ,但不会在我的整数ID中输入

I've tried removing 'type="parameter"'. This puts "id" in the attribute scope, but it doesn't get entered in my Integer id

推荐答案

我不熟悉您正在使用的URL重写器,但您可以单独使用Struts2实现这种映射。

I'm not familiar with the URL re-writer you are using, but you can achieve this sort of mapping with Struts2 alone.

有关<$ c,请参阅此答案 $ C> NamedVariablePatternMatcher 。你需要在struts.xml中设置以下常量:

Please refer to this answer about the NamedVariablePatternMatcher. You'll need the following constants set in your struts.xml:

<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.patternMatcher" value="namedVariable"/>

然后,将您的操作映射为:

Then, map your action as:

<!-- you could also make /promotions a namespace and the action just "abcdef-{id}" -->
<action name="promotions/abcdef-{id}" class="...">
    ...
</action>

这篇关于UrlRewrite Struts2设置参数变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆