📄 00c74bc3f5cc001d15c68b756a903e4c
字号:
package com.csthis.phonebook.struts.action;
import java.lang.reflect.InvocationTargetException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.beanutils.BeanUtils;
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.DynaActionForm;
import org.apache.struts.actions.DispatchAction;
import com.csthit.phonebook.Bean.User;
import com.csthit.phonebook.dao.UserDAO;
public class LoginAction extends DispatchAction {
public ActionForward login(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
HttpSession session = request.getSession();
DynaActionForm loginForm = (DynaActionForm) form;
String username = loginForm.get("username").toString();
String password = loginForm.get("password").toString();
User user = UserDAO.isLogin(username, password);
if (!"".equals(user)) {
session.setAttribute("username", username);
session.setAttribute("uid", user.getUid());
return mapping.findForward("cus");
} else {
return mapping.findForward("fal");
}
}
public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
HttpSession session = request.getSession();
User user = new User();
try {
BeanUtils.copyProperties(form, user);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
int i = UserDAO.register(user);
if (i != 0) {
return mapping.findForward("cus");
} else {
return mapping.findForward("fal");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -