我正在尝试使用 Struts2 验证注释来验证表单,但它似乎不起作用,并且标签上没有显示必需的标记。这是我的代码:
login.jsp
:
<s:form action="/Login" validate = "true">
<table>
<tr>
<td><s:label theme=”simple” required="true">Username :</s:label></td>
<td><s:textfield name="userName" theme=”simple” /></td>
</tr>
<tr>
<td><s:label theme=”simple” required="true">Password :</s:label></td>
<td><s:textfield name="password" theme=”simple” /></td>
</tr>
<tr>
<td><s:submit value="Login" /></td>
</tr>
</table>
</s:form>
LoginAction.java
:
public class LoginAction extends ActionSupport {
private String userName;
private String password;
@Validations(requiredStrings={@RequiredStringValidator(type=ValidatorType.FIELD, message="User Name can ot be empty.", fieldName="userName")})
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
@Validations(requiredStrings={@RequiredStringValidator(type=ValidatorType.FIELD, message="Password can ot be empty.", fieldName="password" )})
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String execute()
{
return SUCCESS;
}
}
struts.xml
:
<struts>
<package name="demo" extends="struts-default">
<action name="*" class="mypkg.action.{0}Action">
<result name="success">/success.jsp</result>
<result name="input">/index.jsp</result>
</action>
</package>
</struts>
有人可以帮助并注意我的代码是否有问题吗?