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

📄 userforgetpasswordaction.java

📁 《基于Eclipse的开源框架技术与实战》[第10章]随书源码
💻 JAVA
字号:
package com.free.web.struts.action;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.free.dao.ISpringHibernateDAO;
import com.free.services.ServiceFinder;
import com.free.web.common.ProjectConstants;
import com.free.web.common.SendMail;
import com.free.web.struts.form.UserForgetPasswordForm;

/**
 * <p>Title: Eclipse Plugin Development</p>
 * <p>Description: Free download</p>
 * <p>Copyright: Copyright (c) 2006</p>
 * <p>Company: Free</p>
 * @author gan.shu.man
 * @version 1.0
 */

public class UserForgetPasswordAction extends Action {
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		//获得ISpringHibernateDAO的实现
		ISpringHibernateDAO springHibernateDAO = ServiceFinder
				.getSpringHibernateDAO(request);

		//获得SendMail的实现
		SendMail mailBean = ServiceFinder
				.getMailBean(request);

		ActionMessages errors = new ActionMessages();
		UserForgetPasswordForm forgetform = (UserForgetPasswordForm) form;

		String strUserName = forgetform.getUsername();
		String strEmail = forgetform.getEmail();

		//获得和用户名与Email相关的密码
		String[] strPasswordEmail = springHibernateDAO
				.retriveUserForgetPassword(strUserName, strEmail);

		if (strPasswordEmail[0] != null && strPasswordEmail[1] != null) {
			System.out.println("Password:" + strPasswordEmail[0]);
			System.out.println("email:" + strPasswordEmail[1]);

			String[] reciepent = { strPasswordEmail[1] };
			String username = strPasswordEmail[2];

			//创建邮件主题
			String subject = "Your username & password ";

			//创建邮件内容
			String message = "Hi," + username;
			message += "\n Your username is " + username + ".";
			message += "\n Your password is " + strPasswordEmail[0] + ".";
			message += "\n Please login to the web site with your username and password.";
			message += "\n \n Thanks";
			message += "\n \n \n Regards";

			String from = ProjectConstants.FROM_MAIL;

			try {
				//发送邮件
				mailBean.sendMail(reciepent, subject, message, from);

			} catch (Exception e) {
				System.out.println("Error in sending mail:" + e);
			}
			return mapping.findForward("success");
		} else {
			errors.add("invalid", new ActionMessage(
					"error.usernameEmail.invalid"));
			saveErrors(request, errors);
			return mapping.findForward("failure");
		}
	}
}

⌨️ 快捷键说明

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