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

📄 loginaction.java

📁 数学网
💻 JAVA
字号:
//Created by MyEclipse Struts// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.0.1/xslt/JavaClass.xslpackage math.login.controller;import java.sql.SQLException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import math.login.dao.LoginDao;import math.login.model.User;import javax.sql.*;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;/** * MyEclipse Struts Creation date: 11-03-2006 *  * XDoclet definition: *  * @struts.action path="/login" name="loginForm" input="/login.jsp" *                parameter="LOGIN" scope="request" validate="true" * @struts.action-forward name="nouser" path="/login.jsp" * @struts.action-forward name="success" path="/index.jsp" */public class LoginAction extends Action {	// --------------------------------------------------------- Instance	// Variables	// --------------------------------------------------------- Methods	private DataSource ds = null;	private org.apache.commons.logging.Log __log = LogFactory.getFactory()			.getInstance(this.getClass());	/**	 * Method execute	 * 	 * @param mapping	 * @param form	 * @param request	 * @param response	 * @return ActionForward	 * @throws SQLException	 */	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 ("LOGIN".equalsIgnoreCase(myaction)) {			myforward = performRetrieve(actionMapping, actionForm,					httpServletRequest, httpServletResponse, 0);		} else if ("ALOGIN".equalsIgnoreCase(myaction)) {			myforward = performRetrieve(actionMapping, actionForm,					httpServletRequest, httpServletResponse, 1);		}else if ("BLOGIN".equalsIgnoreCase(myaction)) {			myforward = performRetrieve(actionMapping, actionForm,					httpServletRequest, httpServletResponse, 2);		}else if ("LOGOUT".equalsIgnoreCase(myaction)) {			myforward = performLogout(actionMapping, actionForm,					httpServletRequest, httpServletResponse);		} else {			myforward = actionMapping.findForward("failure");		}		return myforward;	}	// //////////////////////////////////////////////////////////////	private ActionForward performRetrieve(ActionMapping mapping,			ActionForm form, HttpServletRequest request,			HttpServletResponse response, int in_type) {		ds = getDataSource(request);		LoginForm loginForm = (LoginForm) form;		// ��ʼ��		String username = loginForm.getUsername();		String password = loginForm.getPassword();		// int users_grade= loginForm.getUsers_grade();		// ����dao ����user����		LoginDao logindao = new LoginDao(ds);		User user = new User();		try {			String rand = (String) request.getSession().getAttribute("rand");			// System.out.println("wrrwerwerwer");			if (!loginForm.getRand().equals(rand)) {				sqlNullError(request, 2);				request.getSession().removeAttribute("rand");				if (in_type == 0){					return mapping.findForward("success");					}else if(in_type == 1){						return mapping.findForward("nopruview");					}					else 					{						return mapping.findForward("nopruview");					}			}			user = (User) logindao.finduser(username, password);			if (user == null) {				sqlNullError(request, 1);								if (in_type == 0){				return mapping.findForward("success");				}else if(in_type == 1){					return mapping.findForward("nopruview");				}				else 				{					return mapping.findForward("nopruview");				}											} else {				HttpSession session = request.getSession();				session.setAttribute("USER", user);			}			if (in_type == 0) {								return mapping.findForward("success");			}else if (in_type == 2) {								return mapping.findForward("success");			}else {				if (user.getUsers_grade()>99) {				return mapping.findForward("success");				}else{				return mapping.findForward("nopruview");				}			}		} catch (Exception e) {			generalError(request, e);			return mapping.findForward("failure");		}	}	// //////////////////////////�˳�////////////	private ActionForward performLogout(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response) {		request.getSession().invalidate();		return mapping.findForward("success");	}	private void sqlNullError(HttpServletRequest request, int result) {		// TODO Auto-generated method stub		ActionErrors errors = new ActionErrors();		if (result == 1)			errors.add("notfound", new ActionError("error.input"));		else if (result == 2)			errors.add("erand", new ActionError("error.rand.request"));		saveErrors(request, errors);	}	private void generalError(HttpServletRequest request, Exception e) {		ActionErrors aes = new ActionErrors();		aes.add(aes.GLOBAL_ERROR, new ActionError("error.general", e				.getMessage()));		saveErrors(request, aes);		e.printStackTrace();		if (__log.isErrorEnabled()) {			__log.error(" [Register] Error - " + e.getMessage());		}	}}

⌨️ 快捷键说明

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