UrlRewrite Struts2设置参数变量

编程入门 行业动态 更新时间:2024-10-24 10:18:48
本文介绍了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.

有关 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设置参数变量

本文发布于:2023-11-01 02:25:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547986.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   参数   UrlRewrite

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!