📄 findpasswordaction.java
字号:
package math.reg.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;
import math.reg.dao.FindPassDAO;
import math.reg.model.FindPass;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class FindPasswordAction extends Action {
private DataSource ds = null;
private org.apache.commons.logging.Log __log = LogFactory.getFactory()
.getInstance(this.getClass());
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
ds = getDataSource(httpServletRequest);
ActionForward myforward = null;
String myaction = actionMapping.getParameter();
if (isCancelled(httpServletRequest)) {
if (__log.isInfoEnabled()) {
__log.info(" [Logon] " + actionMapping.getAttribute()
+ " - action was cancelled");
}
return actionMapping.findForward("cancel");
}
if (__log.isInfoEnabled()) {
__log.info(" [Logon] action: " + myaction);
}
if ("".equalsIgnoreCase(myaction)) {
myforward = actionMapping.findForward("failure");
} else if ("FINDPASS".equalsIgnoreCase(myaction)) {
myforward = performFindPass(actionMapping, actionForm,
httpServletRequest, httpServletResponse);
}
else if ("FINDPASSLOGIN".equalsIgnoreCase(myaction)) {
myforward = performFindPassLogin(actionMapping, actionForm,
httpServletRequest, httpServletResponse);
}
else {
myforward = actionMapping.findForward("failure");
}
return myforward;
}
// //////////////////////////////////////////////////////////////
private ActionForward performFindPass(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
try {
HttpSession session =request.getSession();
FindPassDAO regDao = new FindPassDAO(ds);
FindPasswordForm regForm = (FindPasswordForm) form;
if (regForm.getPass_ans() == "") {
// ActionErrors errors = new ActionErrors();
// errors.add("find_error", new
// ActionError("write_hava_error"));
return mapping.findForward("error");
}
FindPass reg = (FindPass)session.getAttribute("FindPasswordForm");
reg.setPass_ans(regForm.getPass_ans());
//BeanUtils.populate(reg, BeanUtils.describe(regForm));
reg = regDao.news(reg);
if (!(reg.getPassword() == "")) {
request.setAttribute("pass",reg);
return mapping.findForward("success");
}
ActionErrors errors = new ActionErrors();
errors.add("find_error", new ActionError("write_hava_error"));
saveErrors(request, errors);
return mapping.findForward("error");
} catch (Exception e) {
// generalError(request, e);
return mapping.findForward("error");
}
}
private ActionForward performFindPassLogin(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
try {
HttpSession session =request.getSession();
FindPassDAO regDao = new FindPassDAO(ds);
FindPasswordForm regForm = (FindPasswordForm) form;
if (regForm.getLost_name() == "" || regForm.getLost_name()==null)
{
// ActionErrors errors = new ActionErrors();
// errors.add("find_error", new
// ActionError("write_hava_error"));
return mapping.findForward("error");
}
FindPass fp = new FindPass();
BeanUtils.populate(fp, BeanUtils.describe(regForm));
fp = regDao.select(fp);
session.setAttribute("FindPasswordForm",fp);
return mapping.findForward("success");
} catch (Exception e) {
// generalError(request, e);
return mapping.findForward("error");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -