I'm not able to see html error message when I enter all 9's or all 0's for ssn and when I submit it is not getting forwarded to the same
jsp again.I get this page cannot be found mesage on submit.What mistake did I do.I'm getting the following errors in the log:
No message text associated with key NULL_MESSAGE_KEY_PASSED in bundle com.ibm.ejs.resources.seriousMessages
E NULL_MESSAGE_KEY_PASSED
My jsp looks like this:
<html:html>
<html:errors/>
<html:form action="pin" method='get' onsubmit="return validate(this)">
<table>
<td align="center">
<html
assword property="SSN1" size="3" maxlength="3" styleClass="field_name"/>
<html
assword property="SSN2" size="2" maxlength="2" styleClass="field_name"/>
<html
assword property="SSN3" size="4" maxlength="4" styleClass="field_name"/>
</td>
<td align="center">
<html:submit property="submit">
</html:submit>
</td>
</table>
</html:form>
</html:html>
my Form is:
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.struts.validator.*;
import org.apache.struts.action.ActionError;
public class PinForm extends ActionForm
{
public void reset(ActionMapping mapping, HttpServletRequest request)
{
this.ssn1 = null;
this.ssn2 = null;
this.ssn3 = null;
}
public
String ssn1 = null;
public String ssn2= null;
public String ssn3= null;
public String getSSN1()
{
return ssn1;
}
public void setSSN1(String ssn1)
{
this.ssn1=ssn1;
}
public String getSSN2()
{
return ssn2;
}
public void setSSN2(String ssn2)
{
this.ssn2=ssn2;
}
public String getSSN3()
{
return ssn3;
}
public void setSSN3(String ssn3)
{
this.ssn3=ssn1+ssn2+ssn3;
}
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
{
ActionErrors errors = null;
errors = super.validate(mapping,request);
if(this.ssn3 == "000000000" || this.ssn3 =="999999999")
{
errors.add("SSN1", new ActionError("error.Invalid SSN.errorMsg"));
}
return errors;
}
}
Action is:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.Action;
public class PinAction extends Action
{
public ActionForward executeAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception
{
final ActionErrors errors = new ActionErrors();
final PinForm pinForm = (PinForm) form;
boolean ssnValid = true;
final String ssn = pinForm.getSSN3();
return mapping.findForward("pin");
}
}
config.xml is:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD
Struts Configuration 1.1//EN"
"struts-config_1_1.dtd">
<struts-config>
<form-beans>
<form-bean name="PinForm" type="xxx.xxx.xxxPinForm"/>
</form-beans>
<action-mappings>
<action path="/pin" type="xxx.xxxx.xxxxx.PinAction" name="PinForm"
scope="request" input="/pin.jsp" validate="true">
<forward name="pin" path="/pin.jsp" />
</action>
</action-mappings>
<message-resources
parameter="resources.ApplicationResources"
null="false" />
<!-- Validator Configuration -->
<plug-in className="org.apache.struts
.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/
validator-rules.xml, /WEB-INF/
validation.xml"/>
</plug-in>
</struts-config>
application resources file is:
error.Invalid SSN.errorMsg=<span class='error_message'> Please enter a valid SSN. {0}</span>
error. No record found.errorMsg=<span class='error_message'> No record found for this SSN. {0}</span>
prompt.no record = No record found for this SSN. {1}
# Struts Validator Error Messages
errors.required={0} is required.
errors.minlength={0} can not be less than {1} characters.
errors.maxlength={0} can not be greater than {1} characters.
errors.invalid={0} is invalid.
errors.byte={0} must be a byte.
errors.short={0} must be a short.
errors.integer={0} must be an integer.
errors.long={0} must be a long.
errors.float={0} must be a float.
errors.double={0} must be a double.
errors.date={0} is not a date.
errors.range={0} is not in the range {1} through {2}.
errors.creditcard={0} is an invalid credit card number.
errors.email={0} is an invalid e-mail address.