Struts2通配符映射 - 更具体的一个由通用映射处理 [英] Struts2 Wildcard Mapping - more specific one is being handled by generic one

查看:103
本文介绍了Struts2通配符映射 - 更具体的一个由通用映射处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用我的Struts2配置进行通配符测试,我坚持使用这个。

I'm currently playing around with my Struts2 config for wildcard testing and I'm stuck with this one.

    <action name="/*/*" class="checkBlogUrl" method="testing">
        <param name="blogSiteUrl">{1}</param>
        <param name="test">{2}</param>
        <result name="success">/WEB-INF/jsp/cmsPages/index.jsp</result>
    </action>

    <action name="/*/postPreview1" class="blogPostAction" method="test">
        <param name="blogSiteUrl">{1}</param>
        <result name="success">/WEB-INF/jsp/cmsPages/templatePicker.jsp</result>
    </action>

如果我访问 myurl.com/hello/hi 我将被重定向到index.jsp

If I access myurl.com/hello/hi I will be redirected to index.jsp

但如果我访问 myurl.com/hello/postPreview1 我也将重定向到 index.jsp 而不是 templatePicker.jsp

But if I access myurl.com/hello/postPreview1 I will also be redirected to index.jsp instead of templatePicker.jsp.

我在这里做错了吗? struts wildcard doc 表示最后一个将获胜

Am I doing something wrong here? The struts wildcard doc said that the last one will win

编辑:
只是试图切换它们并且它工作O_O。我误读了医生吗?

Just tried to switch them around and it worked O_O. Am I misreading the doc?

推荐答案

您正在使用动作名称中的斜杠,这与使用通配符映射器不正确。正如我在链接的答案中所述,在这种情况下,最佳模式匹配器是正则表达式模式匹配器。

You are using slashes in action name, that incorrectly works with wildcard mapper. As I said in the linked answer, the best pattern matcher in this case is the regex pattern matcher.

<constant name="struts.patternMatcher" value="regex"/>

参见高级通配符

<action name="/{blogSiteUrl}/{test}" class="checkBlogUrl" method="testing">
    <result name="success">/WEB-INF/jsp/cmsPages/index.jsp</result>
</action>

<action name="/{blogSiteUrl}/postPreview1" class="blogPostAction" method="test">
    <result name="success">/WEB-INF/jsp/cmsPages/templatePicker.jsp</result>
</action>






关于通配符映射器的文档。让我们看一下示例 blank 应用程序:

<package name="example" namespace="/example" extends="default">

    <action name="HelloWorld" class="example.HelloWorld">
        <result>/WEB-INF/jsp/example/HelloWorld.jsp</result>
    </action>

    <action name="Login_*" method="{1}" class="example.Login">
        <result name="input">/WEB-INF/jsp/example/Login.jsp</result>
        <result type="redirectAction">Menu</result>
    </action>

    <action name="*" class="example.ExampleSupport">
        <result>/WEB-INF/jsp/example/{1}.jsp</result>
    </action>

    <!-- Add actions here -->
</package>






因此URL将按顺序匹配:


So URLs will be matched in the order:


  1. http:// localhost:8080 / example / HelloWorld

  2. http:// localhost:8080 / example / Login_input

  3. http:/ / localhost:8080 / example / Register

  1. http://localhost:8080/example/HelloWorld
  2. http://localhost:8080/example/Login_input
  3. http://localhost:8080/example/Register

我想说更具体的映射在更不具体之前公共映射,它赢了,因为它首先按动作配置的顺序找到。与有序配置不匹配的所有内容都属于最后一个不太具体的映射。

I would say that more specific mapping goes before less specific/common mapping and it wins because it's found first in the order of action configs. Everything that doesn't match the ordered configs fall into last mapping which is less specific.

这篇关于Struts2通配符映射 - 更具体的一个由通用映射处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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