jsp:
<script type="text/javascript">
$().ready(function() {
$("#modifyForm").validate({
rules: {
password:{
required: true,
minlength: 4,
remote: {
url: "user_checkOldPassword.action", //后台处理程序
type: "post", //数据发送方式
// dataType: "json", //接受数据格式
data: { //要传递的其他数据
loginName:$("#loginName").val()
}
}
},
newPassword: {
required: true,
minlength: 4
},
confirm_password: {
required: true,
minlength: 4,
equalTo: "#newPassword"
}
},
messages: {
password: {
remote:"密码错误",
minlength: "不能小于4个字符"
},
newPassword: {
minlength: "不能小于4个字符"
},
confirm_password: {
minlength: "确认密码不能小于4个字符",
equalTo: "两次输入密码不一致"
}
}
});
});
</script>
<tr><td>登录名</td>
<td><s:textfield id="loginName" name="loginName" cssClass="InputStyle2" value="%{#session.user.loginName}" disabled="true"/> *
(登录不可以修改)
</td>
</tr>
<tr><td>旧密码</td>
<td><input id="password" name="password" type="password" class="InputStyle" />
</td>
</tr>
<tr><td>新密码</td>
<td><input id="newPassword" name="newPassword" type="password" class="InputStyle" />
</td>
</tr>
<tr><td>新密码</td>
<td><input id="confirm_password" name="confirm_password" type="password" class="InputStyle" />
</td>
</tr>
java:
private InputStream hint;//返回提示
public String checkOldPassword() throws Exception{
User user=userService.findByLoginNameAndPassword(model.getLoginName(), model.getPassword());
Boolean isExist = false;
if(user!=null){//如果用户不为空
isExist=true;
this.hint= new StringBufferInputStream(isExist.toString());
return "checkOldPasswordHint";
}
this.hint= new StringBufferInputStream(isExist.toString());
return "checkOldPasswordHint";
}
struts.xml
<result name="checkOldPasswordHint" type="stream"><!-- 返回boolean类型 -->
<param name="contentType">text/html</param>
<param name="inputName">hint</param>
</result>