使用struts中的validate方法判断密码不为空
index.jsp:用于输入用户和密码
<body>
<form action="tijiao.action" method="post"><strong>
用户<input type="text" name="username"><br>
密码<input type="password" name="password"><br>
<input type="submit" value="提交"></strong>
<br>
<s:actionerror />
</form>
</body>
show.jsp:用于验证通过后显示
<body>
用户${username}<br>
密码${password}<br>
</body>
yanzheng.java:对提交的界面进行验证
package com;
import com.opensymphony.xwork2.ActionSupport;
public class yanzheng extends ActionSupport {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public void validate() {
if(this.password==null||("").equals(this.password)){
this.addActionError("not null");
}
}
@Override
public String execute() throws Exception {
return "success";
}
}
struts.xml配置:连接jsp与struts.xml
<struts>
<package name="struts2" extends="struts-default">
<action name="tijiao" class="com.yanzheng">
<result name="success">/show.jsp</result>
<result name="input">/index.jsp</result>
</action>
</package>
</struts>