Lorsque j'essaie d'extraire les valeurs de la classe, qui ont été définies dans jsp, null est affiché.Impossible de définir les valeurs de formulaire jsp pour les variables de classe
erreur suivant est observé en mode dev:
ERREUR ParametersInterceptor Notification Developer (set struts.devMode false pour désactiver ce message): Exception inattendue pris paramètre 'nom' sur « org.ravi de classe. EmployeeAction: paramètre d'expression erreur '' avec 't' valeur
Voici mes différentes pages
struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="default" extends="struts-default">
<action name="addEmployeeAction" class="org.ravi.EmployeeAction">
<interceptor-ref name="params" />
<interceptor-ref name="modelDriven"/>
<result name="success">/Add.jsp</result>
</action>
<action name="EmployeeAction" class="org.ravi.EmployeeAction" method="execute">
<interceptor-ref name="params" />
<interceptor-ref name="modelDriven"/>
<result name="success">/index.jsp</result>
</action>
</package>
</struts>
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.util.*,java.io.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<s:form action="Add.jsp" name="addForm">
<table border="1" cellpadding="5">
<tr>
<th>Select</th>
<th>EmpID</th>
<th>Name</th>
<th>City</th>
<th>DoB</th>
</tr>
<tr>
<th><input type="radio" name="record"
onClick="radioValidate(this, 'record')" value="%{var}">
</th>
<th><s:property value="empid"/></th>
<th><s:property value="name"/></th>
<th><s:property value="city"/></th>
<th><s:property value="dob"/></th>
</s:form>
</body>
</html>
Add.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Add New User</h1>
<s:form action="EmployeeAction" >
<s:textfield label="Emp Id" name="empid" />
<s:textfield label="Name" name="name" />
<s:textfield label="City" name="city" />
<s:textfield label="DoB" name="dob" />
<s:submit />
</s:form>
</body>
</html>
EmployeeAction.java
package org.ravi;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class EmployeeAction extends ActionSupport implements ModelDriven<Employee> {
private static final long serialVersionUID = -8136507522861159378L;
private Employee employee=new Employee();
public Employee getEmployee()
{
return employee;
}
public void setEmployee(Employee employee)
{
this.employee=employee;
}
public String execute() throws Exception
{
return SUCCESS;
}
@Override
public Employee getModel()
{
return employee;
}
}
Employee.java
package org.ravi;
import java.io.Serializable;
public class Employee implements Serializable{
static final long serialVersionUID = 1L;
private String empid;
private String name;
private String city;
private String dob;
public void setempid(String empid) {
this.empid = empid;
}
public void setname(String name) {
this.name = name;
}
public void setcity(String city) {
this.city = city;
}
public void setdob(String dob) {
this.dob = dob;
}
public String getempid() {
return this.empid;
}
public String getname() {
return this.name;
}
public String getcity() {
return this.city;
}
public String getdob() {
return this.dob;
}
}
Et la pile d'intercepteurs. –
Cela nécessite que le lien 'Bean' et' CamelCase' soit complet. – AxelH
Je les ai ajouté tellement de fois:/Je l'ai fait maintenant aussi @AxelH, par souci d'exhaustivité ... :) –