gpt4 book ai didi

java - Struts 2.0 请求 Bean 对象获取参数值

转载 作者:行者123 更新时间:2023-12-01 22:54:21 25 4
gpt4 key购买 nike

我有一个 jsp 页面,其员工详细信息的形式如下。

AddEmp.jsp

<th>First Name :</th>
<td><input type = "text" id ="firstName" name = "firstName" value= ""></td>
<th>Middle Name :</th>
<td><input type = "text" id ="middleName" name = "middleName" value= ""></td>
<th>Last Name :</th>
<td><input type = "text" id ="lastName" name = "lastName" value= ""></td>

提交表单后,我在 Controller 中获取了值

public class contTest extends ActionSupport{
public String firstName;
public String lastName;
public String execute(){
System.out.println("firstName-->>>"+firstName);
System.out.println("lastName-->>>"+lastName);
return SUCCESS;
}
}

Struts 2. 0 auto 设置值(定义为Public)并且可以访问它。

我的问题是——!!我有一个 Employee 的 DAO,其中包含如下所有详细信息。

 public class Employee implements java.io.Serializable{
public String firstName;
public String lastName;

public String getFirstName(){
return firstName;
}
public void setFirstName(String firstName){
this.firstName = firstName;
}
public String getLastName(){
return lastName;
}
public void setLastName(String lastName){
this.lastName = lastName;
}
}

一旦我的 HTML 表单从 JSP 提交,我希望将所有字段设置为 DAO,并将直接调用 Controller 内的 DAO,而不是手动定义 Controller 中的每个字段。有人可以帮忙吗?提前谢谢。

P.S:我是 struts 2.0 的新手。

更新 1:谢谢你们的回复。我很嫉妒你的知识。

我试过方式,这就是我真正想要的结果。我接受回复作为答案。 你能告诉我们我们实现的概念的名称吗?我喜欢学习并知道我们的 friend 建议的模型驱动逻辑的好处

谁能用一些简单的例子来详细说明一下吗?

最佳答案

public class contTest extends ActionSupport{
public Employee emp1;
public String execute(){
System.out.println("firstName-->>>"+emp1.getFirstName());
System.out.println("lastName-->>>"+emp1.getLastName());
return SUCCESS;
}

//Create Setter and Getter of emp1 object
}

和 AddEmp.jsp 中

<th>First Name :</th>
<td><input type = "text" id ="firstName" name = "emp1.firstName" value= ""></td>

<th>Last Name :</th>
<td><input type = "text" id ="lastName" name = "emp1.lastName" value= ""></td>

关于java - Struts 2.0 请求 Bean 对象获取参数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24305803/

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