简体   繁体   English

Struts 1:任何Action类的Entry ActionForm输入

[英]Struts 1: Entry ActionForm inputs from any Action class

suppose i want to create form with Struts, so my struts-config will like this: 假设我想用Struts创建表单,因此我的struts-config将如下所示:

<form-bean name="myForm" type="com.MyForm" />


<action path="/entryyourinputs"
    type="com.MyAction" name="myForm"
    input="/myJsp.jsp">

    <forward name="success" path="/regSuccess.jsp" />
</action>

it will show myJsp to assign the myForm. 它将显示myJsp来分配myForm。
my question is how to assign myForm in MyAction instead of the myJsp?. 我的问题是如何在MyAction中分配myForm而不是myJsp?
or what is the method to assign some myForm's inputs from MyAction? 或从MyAction分配一些myForm的输入的方法是什么?

best regards 最好的祝福
Thanks 谢谢

In com.MyForm we need to create getters and setters for that inputs like the following: 在com.MyForm中,我们需要为该输入创建getter和setter,如下所示:

String input;
public String getInput() {return this.input;}

public void setInput(String input) {this.input = input;}

In MyAction which extends struts Action class, we assign values to the MyForm inputs like the following: 在扩展struts Action类的MyAction中,我们将值分配给MyForm输入,如下所示:

public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {
  MyForm myForm = (MyForm) form;
// assigning values to the inputs from action
  myForm.setInput("input value");

 .....
 .....
 .....
}

to get the values in jsp we have to use html tag lib: 要获取jsp中的值,我们必须使用html标签lib:

The Jsp code look like the below code: Jsp代码类似于以下代码:

<html:form action="/entryyourinputs">
   <html:text name="myForm" property="input" />
</html:form>

Note: The html tags must be inside of the **<html:form>** tag. 注意: html标记必须在**<html:form>**标记内。

input fileds in jsp the values which are assigned in MyAction class automatically assigned to the jsp input fields, because of the controller. 在jsp中输入字段,由于控制器的缘故,在MyAction类中分配的值会自动分配给jsp输入字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM