第一种方式
- 在实体类中定义变量(例如变量:ENAME,JOB)
- 在action类中创建对象(例如:对象emp)
- 在jsp页面传值用 对象. 的方式
name="emp.ENAME" value="${emp.ENAME}"
实体类:
public class Emp{
private String ENAME;
private String JOB;
}
action类:
public class EmpSelfAction{
private Emp emp=new Emp();
public String editConfig(){
System.out.println(emp.getENAME());
System.out.println(emp.getJOB());
return SUCCESS;
}
}
jsp页面进行接收Action传来的值:
<tr>
<th>员工姓名 </th>
<td style="text-align: center; white-space: nowrap;" width="50%">
<input name="emp.ENAME" value="${emp.ENAME}" style="width: 100%; height: 100%;border:0pt; background-color:white;" />
</td>
</tr>
<tr>
<th>职位</th>
<td style="text-align: center; white-space: nowrap;" width="50%">
<input name="emp.JOB" value="${emp.JOB}" style="width: 100%; height: 100%;border:0pt; background-color:white;" />
</td>
</tr>
第二种方式
- 在action中定义属性(例如:ENAME,JOB(该属性可以是实体类中的属性,也可以是新定义的))
- 在jsp页面把属性传进去。(例如: name=“ENAME” value="${ENAME}")
name="ENAME" value="${ENAME}"
action类:
public class EmpSelfAction{
private String ENAME;
private String JOB;
public String editConfig(){
System.out.println(ENAME);
System.out.println(JOB);
return SUCCESS;
}
}
jsp页面进行接收Action传来的值:
<tr>
<th>员工姓名 </th>
<td style="text-align: center; white-space: nowrap;" width="50%">
<input name="ENAME" value="${ENAME}" style="width: 100%; height: 100%;border:0pt; background-color:white;" />
</td>
</tr>
<tr>
<th>职位</th>
<td style="text-align: center; white-space: nowrap;" width="50%">
<input name="JOB" value="${JOB}" style="width: 100%; height: 100%;border:0pt; background-color:white;" />
</td>
</tr>