struts2中数据如何从action类传输到Jsp页面

发布于 2024-10-26 05:05:31 字数 85 浏览 2 评论 0原文

struts2中数据如何从action类传输到Jsp页面。 在将其控制权转移到 jsp 页面之前,是否在操作类内部构建了任何类型的堆栈,或者使用了其他机制。

How the data transfer from the action class to Jsp page in struts2.
Is any kind of stack is build inside the action class before its transfer its control to the jsp page , or there is something other mechanism is used for that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

用心笑 2024-11-02 05:05:31

Anshul,

您的实现有些正确。对于 Struts2,我们可以通过以下方式查看它

  1. ValueStack
  2. OGNL

值堆栈是 Struts2 框架中的虚拟堆栈,是框架放置与请求处理相关的所有数据的中心位置。在 Struts2 中,操作也被视为数据载体,因此确切发生的情况是,当操作完成其工作时,它被放置在值堆栈的顶部。

现在让我们在 Action 中拥有类似的东西,

public class MyAction extends ActionSupport{

  private String firstname;
  private String lastname;

  public void setFirstName(firstname){
     this.firstname=firstname
  }

 public void setLastName(lastname){
     this.lastname=lastname
  }

public String getFirstName(){
   return firstname;
}

public String geLastName(){
   return lastname;
}

 public String execute() throws Exception{
             //action logic filling first name and last name from database etc.
             return SUCCESS;
 }
}

逻辑框架将 Action 实例放置在值堆栈的顶部并且 firstnamelastname 将位于顶部后,action 将返回它的。

so now when we try to access these values in jsp something like
<s:textfield name="firstname" value= "%{firstname}"/>

这里 (%{firstname}) OGNL 将到位,它将尝试查看值堆栈中是否存在名为 firstname 的属性,因为操作已开启位于值堆栈的顶部,并且其中包含属性名称 firstname,因此 OGNL 会找到它。

我希望这会帮助你

Anshul,

You are some what correct in your implementation.For Struts2 we can see it in following manners

  1. ValueStack
  2. OGNL

Value stack is a virtual stack in Struts2 framework and a central place where all the data related to request processing will be placed by the Framework.In Struts2 Actions are also treated as a data carrier, so what exactly is happening is when the action done its work it is being placed on the top of value stack.

Lets we have something like this in Action

public class MyAction extends ActionSupport{

  private String firstname;
  private String lastname;

  public void setFirstName(firstname){
     this.firstname=firstname
  }

 public void setLastName(lastname){
     this.lastname=lastname
  }

public String getFirstName(){
   return firstname;
}

public String geLastName(){
   return lastname;
}

 public String execute() throws Exception{
             //action logic filling first name and last name from database etc.
             return SUCCESS;
 }
}

now when action will return after the logic framework will place action instance on the top of value stack and firstname and lastname will be on the top of it.

so now when we try to access these values in jsp something like
<s:textfield name="firstname" value= "%{firstname}"/>

here (%{firstname}) OGNL will come in to place and it will try to see if there is a property in the value stack with name firstname,since action is on the top of value stack and it has property name firstname in it so OGNL will find it.

i hope this will help you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文