609b68b8f5cc001d15c68b756a903e4c

来自「用struts框架做的jsp通讯录」· 代码 · 共 57 行

TXT
57
字号

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;
import com.sun.jndi.ldap.BerDecoder;

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");
			}
		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");
		}
	return mapping.findForward("fal");
	}
}

⌨️ 快捷键说明

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