ssh项目中修改密码

相关配置文件

CommonManager.xml

<bean id="updatePasswordAction" class="cn.itsouce.pss.web.UpdatePasswordAction"
	scope="prototype">
	<property name="employeeService" ref="employeeService" />
</bean>

 struts.xml

 

<!-- 处理修改密码 -->
<action name="updatePassword_*" class="updatePasswordAction" method="{1}">
	<result>/WEB-INF/jsps/updatePassword.jsp</result>
</action>

 后台Action处理的代码

 

package com.liuzm.mypss.web;

import org.apache.struts2.ServletActionContext;

import com.liuzm.mypss.domain.Employee;
import com.liuzm.mypss.service.IEmployeeService;
import com.liuzm.mypss.utils.MD5Encrypt;

public class UpdatePasswordAction extends BaseAction {

	private IEmployeeService employeeService;

	private String oldPassword;
	private String newPassword;

	public void setEmployeeService(IEmployeeService employeeService) {
		this.employeeService = employeeService;
	}

	@Override
	public String execute() throws Exception {
		System.out.println("employeeService====="+employeeService);
		return SUCCESS;
	}

	public String update() throws Exception {
		// 从session中获取用户
		Employee employee = (Employee) ServletActionContext.getRequest()
				.getSession().getAttribute(LOGIN_USER);
		oldPassword = MD5Encrypt.INSTANCE.encrypt(oldPassword);
		if (employee.getPassword().equals(oldPassword)) {// 旧密码输入正确
			newPassword = MD5Encrypt.INSTANCE.encrypt(newPassword);
			employee.setPassword(newPassword);
			employeeService.update(employee);
			// 销毁HttpSession里面的登录用户
			ServletActionContext.getRequest().getSession()
					.removeAttribute(LOGIN_USER);
			return LOGIN;
		}else {
			addActionError("旧密码输入错误!");
			return SUCCESS;
		}
	}

	public String getOldPassword() {
		return oldPassword;
	}

	public void setOldPassword(String oldPassword) {
		this.oldPassword = oldPassword;
	}

	public String getNewPassword() {
		return newPassword;
	}

	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}

}

 前台页面表单和相关js验证

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link href="css/index.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" media="screen"
	href="js/validate/css/screen.css" />
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/validate/jquery.validate.js" type="text/javascript"></script>
<script src="js/validate/messages_cn.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
$().ready(function() {
	$("#updatePasswordForm").validate({
		rules: {
			oldPassword: {
				required: true,
				minlength: 5
			},
			newPassword: {
				required: true,
				minlength: 5,
				equalNotTo:"#oldPassword"
			},
			confirmPassword: {
				required: true,
				minlength: 5,
				equalTo: "#newPassword"
			}
		},
		messages:{
			newPassword: {
				equalNotTo:"新密码和旧密码不应该相同"
			},
			confirmPassword:{
				equalTo: "确认密码和新密码不一致"
			}
		}
	});	
});
//-->
</script>
<title>成都蓝源进销存系统(教学版)-系统主页</title>
</head>
<body>

<%@ include file="/WEB-INF/views/message.jsp" %>
<s:form id="updatePasswordForm" action="updatePassword_update" method="post">
	<table width="100%"  border="0" cellpadding="0" cellspacing="0">
	<tr bgcolor="#FFFFFF">
      <td width="22%" height="30" align="center">旧密码:</td>
      <td width="29%">
      <s:textfield id="oldPassword" name="oldPassword" />
      </td>
    </tr>

	<tr bgcolor="#FFFFFF">
      <td width="22%" height="30" align="center">新密码:</td>
      <td width="29%">
      <s:textfield id="newPassword" name="newPassword" />
    </tr>

	<tr bgcolor="#FFFFFF">
      <td width="22%" height="30" align="center">确认密码:</td>
      <td width="29%">
      <s:textfield name="confirmPassword" />
      </td>
    </tr>

	<tr bgcolor="#FFFFFF">
      <td width="22%" height="30" align="center"></td>
      <td width="29%">
    	 <s:submit value="修改密码" />
      </td>
    </tr>
    </table>
	</s:form>
	<!--"content-right"end-->
</body>
</html>


 

 

 

 

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值