【问题标题】:Struts2 Lifecycle of Action objectStruts2 Lifecycle of Action 对象
【发布时间】:2013-01-28 17:38:59
【问题描述】:

我是 Struts2 框架的新手,我真的没有太多时间阅读任何 Struts2 书籍。我只是从 YouTube 上学习的。无论如何,这是我的问题。

据说我的 struts.xml 如下:

<struts>
<package name="p1" namespace="/" extends="struts-default">
    <action name="login" class="org.tutorial.struts2.action.LoginAction">
        <result name="success"  type="redirect" >searchTutorialForm</result>
        <result name="error">/login.jsp</result>
    </action>
    <action name="searchTutorialForm">
        <result>/searchForm.jsp</result>
    </action>
</package>  
</struts>

让我们谈谈包 p1。

如果 URL 是 [http://localhost:8080/Struts2/login],则调用 org.tutorial.struts2.action.LoginAction 并在成功后重定向到调用 searchForm 的 searchTutorialForm 操作标记。 jsp.

所以客户端看到的 URL 是 [http://localhost:8080/Struts2/searchTutorialForm] (目的不是让客户端看到[http://localhost:8080/Struts2/searchForm.jsp])

现在 LoginAction 中有一些成员变量正在使用标签显示在 searchForm.jsp 中。但是使用这种方法,它们不会显示,因为我认为对象 LoginAction 不再在 ValueStack 中(在重定向之后,我想??)。

当然,如果我不使用上述方法,而是按照以下方法:

<struts>
<package name="p1" namespace="/" extends="struts-default">
    <action name="login" class="org.tutorial.struts2.action.LoginAction">
        <result name="success">/searchForm.jsp</result>
        <result name="error">/login.jsp</result>
    </action>
</package>  
</struts>

然后使用标签将 LoginAction 对象中的成员变量显示在 success.jsp 中(但随后用户会看到 URL [http://localhost:8080/Struts2/searchForm.jsp])

基本上,我的目的是让用户看不到任何特定的内部文件或像 .jsp 或 .action 这样的调用。

重要提示: 动作标签 searchTutorialForm 中没有动作类 - 基本上是一个虚拟动作。

问题:
1. 如何使用第一种方法在 LoginAction 对象中显示成员变量?
2、Value Stack中LoginAction对象的生命周期是怎样的?

谢谢。

【问题讨论】:

    标签: struts2


    【解决方案1】:
    • 根据请求创建操作。
    • 重定向会导致新请求。
    • 因此,之前操作中的对象不再可用。

    问题:

    1. 您将其放入会话中或将它们作为参数包含在重定向中。
    2. 操作在请求结束时消失。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-24
      • 1970-01-01
      • 1970-01-01
      • 2016-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多