大家好,
这不是一个真正的问题,但我想知道如何限制以下行为。
我在 stuts.xml 文件中设置了此设置。
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.custom.i18n.resources" value="ApplicationResources" />
<package name="default" extends="struts-default" namespace="/">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<action name="blue">
<result name="success" type="tiles">/blue.tiles</result>
</action>
<action name="yellow">
<result name="success" type="tiles">/yellow.tiles</result>
</action>
<action name="red">
<result name="success" type="tiles">/red.tiles</result>
</action>
</package>
</struts>
现在困扰我的是,这些行动是可以接受的:
http://localhost:port/blue
http://localhost:port/yellow
http://localhost:port/red
但您也可以像这样访问它们。
http://localhost:port/yellow/blue/
http://localhost:port/red/blue/yellow
所以ti触发“/".
之后提到的所有动作我想阻止这种情况发生,所以我想知道是否有任何方法可以限制它?
提前谢谢, 亚历答案 0 :(得分:2)
在web.xml
中你可能有一个类似于struts动作映射的条目
<servlet-mapping>
<servlet-name>struts2</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
根据servlet规范A string beginning with a ‘/’ character and ending with a ‘/*’ suffix is used for path mapping
因此,如果您想要提供绝对网址映射,则必须指定它们,如下所示
<servlet-mapping>
<servlet-name>struts2</servlet-name>
<url-pattern>/blue</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>struts2</servlet-name>
<url-pattern>/yellow</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>struts2</servlet-name>
<url-pattern>/red</url-pattern>
</servlet-mapping>
如果您使用struts 2.1.7或更高版本,则可以添加如下所示的排除模式
<constant name="struts.action.excludePattern" value="/([a-zA-Z0-9]+)/.*"/>