gpt4 book ai didi

java - Struts2,使用 method={1} 的最佳实践

转载 作者:数据小太阳 更新时间:2023-10-29 02:18:23 24 4
gpt4 key购买 nike

我是 Struts 2 的新手,我遇到过这种语法(在教程中推荐)。

<action name="Register_*" method="{1}" class="Register">
<result name="input">/member/Register.jsp</result>
<result type="redirectAction">Menu</result>
</action>

我知道它调用 Register.{1} 方法。问题是用户可以输入另一个(随机)值并导致 500 错误(这将被正确记录为错误)。

如何预防?

最佳答案

在我的应用程序中,我们这样使用它:

  <action name="*/*" class="{1}Action" method="{2}">
<interceptor-ref name="CustomAuthStack" />
<result>/pages/{1}/{2}.jsp</result>
<result name="input">/pages/error/denied.jsp</result>
<result name="logout">/pages/error/denied.jsp</result>

<!-- methods that come back to listing after processing -->
<result name="remove" type="redirectAction">{1}/list</result>
<result name="save" type="redirectAction">{1}/list</result>
<result name="enable" type="redirectAction">{1}/list</result>

....

</action>

对于像 myapp/users/list 这样的斜杠,你必须使用

<constant name="struts.enable.SlashesInActionNames" value="true" />

在 strus.xml 中。

现在你有了一个标准:

Action --> UserActionjsp -----> 用户/list.jsp

等等

关于java - Struts2,使用 method={1} 的最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/729885/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com