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

📄 loginaction.java

📁 一段很有意义的源码,看了就知道,不信试一试啊!
💻 JAVA
字号:
package com.sofmit.tools;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.wondersgroup.framework.security.bo.SecurityUser;
import com.wondersgroup.framework.security.exception.AuthenticationException;
import com.wondersgroup.framework.security.service.AuthenticationService;
import com.wondersgroup.framework.security.service.UserService;

/**
 * @author fanjibin
 * 
 */
public class LoginAction extends BaseAction {

	final static Log logger = LogFactory.getLog(LoginAction.class);
	public AuthenticationService authenticationService;
	public UserService userService;
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ActionMessages errors = new ActionMessages();
		LoginForm loginForm = (LoginForm) form;
		String loginName = loginForm.getLoginName();
		String strFlag=loginForm.getStrFlag();
		String id=loginForm.getId();
		String password = loginForm.getPassword();
       
		boolean isValid = true;
		try {
			authenticationService=(AuthenticationService)getService("authenticationService",request);
			userService=(UserService)getService("userService",request);
//			isValid = authenticationService.authentication(loginName, password);
			if (isValid) {
//				SecurityUser user = userService.getUserByLoginName(loginName);
				request.getSession().setAttribute(Constants.LOGIN_NAME, loginName);
//				request.getSession().setAttribute(Constants.UAAS_USER, user);
				request.getSession().setAttribute(Constants.SECURITY_LOGIN_ID,id);
				//Cookie loginCook = new Cookie(Constants.LOGIN_NAME, loginName);
				//Cookie userIdCook = new Cookie(Constants.COOKIE_LOGIN_ID, String.valueOf(user.getId()));
				//loginCook.setMaxAge(-1);
				//userIdCook.setMaxAge(-1);
				//loginCook.setPath("/");
				//userIdCook.setPath("/");
				//response.addCookie(userIdCook);
				
//				String loginnametest=request.getSession().getAttribute(Constants.LOGIN_NAME).toString();
				System.out.println(loginName);
				System.out.println(password);
//				System.out.println(loginnametest);
			//	response.addCookie(loginCook);
		//		SecurityUser[] securityUsers=userService.getUsersByProxy(user,true); 
			//	if (securityUsers!=null&&securityUsers.length>0)
			//		return (mapping.findForward(Constants.STRUTS_PROXY));
			//	else
					return (mapping.findForward("success"));
			}
		} catch (AuthenticationException e) {
			errors.add("LoginFormMessage", new ActionMessage(e.getMessage()));
			logger.error(e.getMessage());
		}

		if (!errors.isEmpty()) {
			saveErrors(request, errors);
		}
		return (mapping.findForward(Constants.STRUTS_FAILURE));
	}
}

⌨️ 快捷键说明

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