java - 如何将 "/user/{user_id}"之类的 URL 映射到特定操作?

标签 java regex struts2 wildcard wildcard-mapping

如何将正则表达式数字类 (\d) 映射到操作?

示例:

/user/123 , /user/345,  /user/546456 ....

最佳答案

Advanced Wildcards :

Advanced Wildcards

From 2.1.9+ regular expressions can be defined defined in the action name. To use this form of wild card, the following constants must be set:

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

The regular expressions can be in two forms, the simplest one is {FIELD_NAME}, in which case the field with the FIELD_NAME in the action will be populated with the matched text, for example:

<package name="books" extends="struts-default" namespace="/">
    <action name="/{type}/content/{title}" class="example.BookAction">
        <result>/books/content.jsp</result>
    </action> 
</package>

In this example, if the url /fiction/content/Frankenstein is requested, BookAction's field "type" will be set to "fiction", and the field "title" will be set to "Frankenstein".

请注意,如果您需要在 prepare() 方法中使用这些参数,you need a tuned up Interceptor Stack .

关于java - 如何将 "/user/{user_id}"之类的 URL 映射到特定操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22468354/

相关文章:

java - Spring注解与xml混合问题

java - 是否有任何解析器可以将 SQL 转换为树(AST)?

正则表达式移动和更改文件名

java - java用正则表达式匹配字符串数组内容

javascript - 匹配起始字符串和可能的终止字符串之间的所有内容

jquery - 如何从mysql数据库显示struts2 jquery网格中的blob类型?

jquery - Struts2/jQuery : resume link href redirect after e. PreventDefault();

java - 使用Java从Linux上的图像获取路径

java - 将字符串转换为整数 val

html - Struts2:不同大小的文本框