第一種方式
- 在實體類中定義變量(例如變量: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>