📄 forgotpwaction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.shopping.struts.action.user;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.shopping.bo.user.ForgotPW;
import com.shopping.dao.UnifyDao;
import com.shopping.factory.DAOFactory;
import com.shopping.vo.User;
public class ForgotPWAction extends DispatchAction {
public ActionForward first(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String name = request.getParameter("name");
String email = request.getParameter("email");
UnifyDao ud = null;
try {
ud = (UnifyDao) DAOFactory
.getBean("com.shopping.dao.imp.UserDaoImp");
} catch (InstantiationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalAccessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (ud.getTableByName(name) != null) {
User user = (User) ud.getTableByName(name);
if (user.getEmail().equals(email)) {
request.getSession().setAttribute("name", name);
return new ActionForward("/forgotPW2.jsp");
} else {
request.setAttribute("info", "wrong");
return new ActionForward("/forgotPW1.jsp");
}
}
return null;
}
public ActionForward second(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String name = (String) request.getSession().getAttribute("name");
String question = request.getParameter("question");
String answer = request.getParameter("answer");
String password = request.getParameter("newPW");
UnifyDao ud = null;
try {
ud = (UnifyDao) DAOFactory
.getBean("com.shopping.dao.imp.UserDaoImp");
} catch (InstantiationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalAccessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ForgotPW f = new ForgotPW();
if (f.checkQA(question, answer, name)) {
User user = (User) ud.getTableByName(name);
user.setPassword(password);
ud.updateTable(user);
request.setAttribute("info", "changeSuccess");
return new ActionForward("/login.jsp");
} else {
request.setAttribute("info", "wrong2");
return new ActionForward("/forgotPW1.jsp");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -