struts中validate简单验证

使用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>    



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值