验证在页面加载时发生。错误消息显示为页面加载。
我的 index.jsp 看起来像
<body>
Employee Information :
<s:form action="empinfo" method="post">
<s:textfield name="name" label="Name" size="20" />
<s:textfield name="age" label="Age" size="20" />
<s:select name="gender" headerKey="0" headerValue="Select Gender"
label="gender" list="#{'1':'Male','2':'Female'}" />
<s:textfield name="email" label="Email" size="20" />
<s:textfield name="phone" label="Phone_Number" size="20" />
<s:submit name="submit" label="Login" align="center" />
</s:form>
</body>
动作类(Employee.java)
public String execute()
{
return SUCCESS;
}
验证文件 Employee-validation.xml:
<field name="name">
<field-validator type="requiredstring">
<message>
The name is required.
</message>
</field-validator>
</field>
<field name="age">
<field-validator type="required">
<message>
The age is required.
</message>
</field-validator>
</field>
struts.xml 文件为:
<action name="empinfo"
class="com.tutorialspoint.struts2.Employee"
method="execute">
<result name="init">/index.jsp</result>
<result name="input">/index.jsp</result>
<result name="success">/Edit.jsp</result>
</action>
单击提交后,我应该怎么做才能验证表单?struts.xml 文件是否需要为此进行任何配置?