我是Struts的新手。我遇到了问题。我试图将JSP表单值填充到Action类中,但我没有在Action类中获取值。谁能告诉我什么是问题?这是我的JSP。
addEmployee.jsp
<a:form action="addEmployee">
<a:textfield name="eId" size="20" label="EmployeeID"/>
<a:textfield name="eName" size="20" label="EmployeeName"/>
<a:textfield name="eCity" size="20" label="EmployeeCity"/>
<a:submit value="ADD EMPLOYEE" ></a:submit>
</a:form>
我的动作类 - AddEmployeeAction.java
package com.action;
import com.opensymphony.xwork2.ActionSupport;
public class AddEmployeeAction extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
int eId;
String eName;
String eCity;
public AddEmployeeAction(){
}
@Override
public String execute() throws Exception{
System.out.println("*******Execute*******"+eId+eName+eCity);
return "success";
}
public int geteId() {
return eId;
}
public void seteId(int eId) {
this.eId = eId;
}
public String geteName() {
return eName;
}
public void seteName(String eName) {
this.eName = eName;
}
public String geteCity() {
return eCity;
}
public void seteCity(String eCity) {
this.eCity = eCity;
}
}
我的配置文件 - struts.xml
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<package name="default" extends="struts-default" namespace="/">
<action name="addEmployee" class="com.action.AddEmployeeAction">
<result name="success">/response.jsp</result>
<result name="input">/addEmployee.jsp</result>
</action>
</package>
</struts>
答案 0 :(得分:1)
你的getter和setter命名不正确;他们应该遵循JavaBean命名约定:
public String getEName() {
return eName;
}
public void setEName(String eName) {
this.eName = eName;
}
就个人而言,我要么:
empName
,employeeName
或employee.name
等,或ModelDriven<Employee>
不相关,但标签应该是人类可读的,例如“员工姓名”,而不是像骆驼一样的Java-esque字符串。