Struts 2.0向Bean对象请求getparameter值 [英] Struts 2.0 request getparameter values to Bean object

查看:77
本文介绍了Struts 2.0向Bean对象请求getparameter值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jsp页面,其中包含以下员工详细信息的形式.

I have a jsp page having form of employee details as below.

AddEmp.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>

提交表单后,我在控制器中得到了值

After Submit the form i got the values in the 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会自动设置值(定义为Public)并可以访问它.

The Struts 2.0 automatically set the values(defined as Public) and can able to access it.

我的问题是-!!我有一个员工的DAO,其中包含以下所有详细信息.

My question is --!! i have a DAO of Employee having all the details like below.

 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,并将直接在控制器内部调用DAO,而不是在控制器中手动定义每个字段.有人可以帮忙吗?提前谢谢.

Once my HTML form submits from the JSP i want all the fields to be set to the DAO and will directly call the DAO inside the controller instead manually defined each fields in the controller. Can Anybody help on this.? Thx in advance.

P.S:我是Struts 2.0的新手.

P.S : i am new to struts 2.0.

更新1: 谢谢你们的回应.我嫉妒您的知识.

Update 1 : Thanks Guys For your response. And i am Jealous on your Knowledge.

我尝试了的方式,这就是结果我正是想要的. 我接受答复作为答案. 的问题,您能告诉我们这个概念的名称吗?已实现,并且我想学习并了解我们的朋友.

I tried msr way and thats what the result i exactly want. I accept msr reply as the Answer. msr can u please tell the name of the concept we implemented and i like to learn and knew the benefits of the ModelDriven Logic suggested by our friend alexander.

任何人都可以列举一些简单的例子吗?

Can any one pls elaborate with some simple example?

推荐答案

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

and in 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>

这篇关于Struts 2.0向Bean对象请求getparameter值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆