this post您让我清楚如何处理Struts中的JAVA对象;struts2 +将表单值设置为POJO并将POJO值设置为
JSP
<th>First Name :</th>
<td><input type="text" id ="em.firstName" name="em.firstName" value=""></td>
<th>Middle Name :</th>
<td><input type="text" id ="em.middleName" name="em.middleName" value=""></td>
<th>Last Name :</th>
<td><input type="text" id ="em.lastName" name="em.lastName" value=""></td>
Action类
public class contTest extends ActionSupport{
public Employee em;
public String execute(){
System.out.println("firstName-->>>"+em.getFirstName());
System.out.println("lastName-->>>"+em.getLastName());
return SUCCESS;
}
//Setter and Getter of em object
}
现在我想使用相同的JSP其中I取从数据库中的数据(和使用雇员对象适合值返回到表格)也用于更新。
如何映射em.firstName与Object firstName变量?
编辑1:
编辑...
**更新3:**
希望现在将其清除。
首先我选择员工,然后单击开始按钮。
$('#Go').click(function(){
if($("#txtEmpId").val() == "" || $("#txtEmpId_name").val()==""){
alert("Please Select Employee.");
return false;
}
$.ajax({
type: 'POST',
url: 'EmpView.action',
data: $("#FrmEmp").serialize(),
}).done(function(data) {
$("#FrmEmp").submit();
});
$('#EmployeeDet,#divEmpId').show();
});
struts.xml中
<action name="EmpView" class="com.Test.Controller.EmpCntr" method= "EmpView">
/*I tried with Both*/
<result name = "success" type="json"/>
or
<result name="success">/AddEmp.jsp</result>
</action>
动作类别:
public String EmpView() throws SQLException, IOException{
System.out.println("em.firstName--->>>"+em.getFirstName());
System.out.println("em.lastName--->>>"+em.getLastName());
try {
CachedRowset tmList = TmMo.GetEmpViewData(ProcName,ParaName);
int numcols = tmList.getMetaData().getColumnCount();
List <String> row = new ArrayList<>(numcols);
while (tmList.next()) {
for (int i=1; i<= numcols; i++) {
row.add(tmList.getString(i));
em.setEmployeeId(tmList.getString("employeeId"));
em.setFirstName(tmList.getString("firstName"));
}
}
System.out.println("em.firstName--->>>"+em.getFirstName());
System.out.println("em.lastName--->>>"+em.getLastName());
/*Here i am getting the Name */
} catch (Exception e) {
e.printStackTrace();
}
return Action.SUCCESS;
}
AddEmp.jsp
Go按钮:
<td>
<button type = "button" name = "Go" id= "Go">Go</button>
<button type = "button" name = "Add" id= "Add">Add Employee</button>
</td>
表单域:
<th>First Name :</th>
<td><input type = "text" id ="em.firstName" name = "em.firstName" value = "<s:property value='em.firstName'/>" ></td>
or
<s:textfield id ="em.firstName" name = "em.firstName"/>
我试用过的方式和清除是我想做的路径。删除了所有不需要的东西,并仅放入示例代码并仅尝试使用示例代码。它不工作!我可以清理你吗?你能帮助我,我错过了吗?
请停止使用[tag:]在您的问题描述中打电话给别人...... 1)不工作,2)错了,3)很丑,4)没用, –
雅凛当然..不会那么做时间。你不知道答案? – Romeo
您在这里没有任何jQuery。你的对象是'emp'而不是'em'。 –