我正在使用 Struts 2 开发 Web 应用程序。我有行动类实施ActionSupport
。我的问题是当我输入一些文本错误消息时没有被清除,表单也没有被提交。
这是我所拥有的:
CustomerAction.java
:
public class CustomerAction extends ActionSupport
{
private Customer customer = new Customer();
private String customerName;
private String emailID;
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public Customer getCustomer() {
return customer;
}
/**
* @param customer
*/
public void setCustomer(Customer customer) {
this.customer = customer;
}
public String getEmailID() {
return emailID;
}
public void setEmailID(String emailID) {
this.emailID = emailID;
}
public void validate()
{
if (customerName == null)
{
addFieldError("customer.customerName","Required");
}
if (emailID == null || emailID.trim().equals(""))
{
addFieldError("customer.emailID","Email is Required");
}
}
Struts.xml
:
<action name="addCustomer" class="com.yell.hibu.action.CustomerAction" method="execute">
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*,^struts\..*</param>
</interceptor-ref>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param></interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<result name="input">/registration.jsp</result>
<result name="success">/success.jsp</result>
</action>
</package>
</struts>
regisration.jsp
:
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Customer Registration Form</title>
<s:head/>
</head>
<body>
<br>
<br>
<center>
<table width="450" align="center">
<tr>
<td align="center" height="40"><font
style="color: #003300; font-family: fantasy !important;"><strong
style="color: #003300 !important;">Registration Form</strong></font></td></tr>
<tr>
<td width="1000" align="center"><br> <font color="#003300"><s:actionerror/>
<s:form action="addCustomer" id="register-form" method="post" theme="xhtml" enctype="multipart/form-data">
<s:textfield name="customer.customerID" label="Customer ID" size="15" />
<s:textfield name="customer.customerName" label="Customer Name:" maxlength="10"/>
</s:form>
</body>
</head>
</html>