⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userpswupdateaction.java

📁 使用J2EE Struts开发的房地产信息咨询系统
💻 JAVA
字号:
/**
 * 修改注册用户的密码的Action Bean
 * userPswUpdate.java
 * @author usr
 */

package building;

import javax.sql.*;
import javax.servlet.http.*;
import javax.servlet.ServletContext;
import org.apache.struts.action.*;

public final class UserPswUpdateAction extends Action
{
	public ActionForward execute(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response)
	throws Exception
	{
		DynaActionForm userPswForm = (DynaActionForm)form;
		
		String oldPsw = (String)userPswForm.get("oldPsw");
		String newPswX = (String)userPswForm.get("newPswA");
		String newPswY = (String)userPswForm.get("newPswB");
		
		//CharSet
		oldPsw = CharSet.GBK_ISO(oldPsw);
		newPswX = CharSet.GBK_ISO(newPswX);
		newPswY = CharSet.GBK_ISO(newPswY);
		
		//
		HttpSession session = request.getSession(true);
		String userName = (String)session.getAttribute(Constants.LOGIN_USERNAME_KEY);
		
		//
		ServletContext context = servlet.getServletContext();
		DataSource dataSource = (DataSource)context.getAttribute(Constants.DATASOURCE_KEY);
		DB db = new DB(dataSource);
		//
		String PageForward = null;
		ActionMessages errors = null;
		//
		if ( !newPswX.equals(newPswY) )
		{
			//新密码不相同
			errors.add(ActionMessages.GLOBAL_MESSAGE,
					new ActionMessage("errors.userPswUpdateFail"));
			if (!errors.isEmpty())
			{
				saveErrors(request,errors);
			}//End of if
			
			PageForward = "toWrong";
		}//End of if
		else
		{
			if ( Users.checkUser(db,userName,oldPsw) )
			{
				//用户身份验证成功
				if ( Users.updatePsw(db,newPswX,userName) )
				{
					//用户密码更新成功
					PageForward = "toUserPswUpdateOK";
				}//End of if
				else
				{
					//用户密码更新失败
					errors.add(ActionMessages.GLOBAL_MESSAGE,
							new ActionMessage("errors.userPswUpdateFail"));
					if (!errors.isEmpty())
					{
						saveErrors(request,errors);
					}//End of if
					
					PageForward = "toWrong";
				}//End of else
			}//End of if
			else
			{
				//用户身份验证失败
				errors.add(ActionMessages.GLOBAL_MESSAGE,
						new ActionMessage("errors.userPswUpdateFail"));
				if (!errors.isEmpty())
				{
					saveErrors(request,errors);
				}//End of if
				
				PageForward = "toWrong";
			}//End of else
		}//End of else
		
		
		//
		db.close();
		
		return(mapping.findForward(PageForward));
	}//End of execute
	
}//End of class userPswUpdate

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -