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

📄 logonaction.java

📁 本人课程设计时做的一个用struts框架实现的基于cmmi2的项目管理系统的原型。还有部分功能尚未实现
💻 JAVA
字号:
package com.cmmi2pms.logon;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
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;
import org.apache.struts.action.ActionServlet;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;

import org.apache.log4j.Logger;

import com.cmmi2pms.common.comdb.*;
import com.cmmi2pms.sa.user.Employee;
import com.cmmi2pms.common.*;




public final class LogonAction extends Action {


    private static Logger logger = Logger.getLogger ("LogonAction") ;
    
    private String perm = null;
    
    /**
     * Validate credentials with business tier.
     *
     * @param username The username credential
     * @param password The password credential
     * @returns true if credentials can be validated
     * @exception UserDirectoryException if cannot access directory
     */
   /*
    public boolean isUserLogon(String username,
        String password)  {

        try{
					//PooledConnectionMgr.getInstance().initialize(30,"192.168.15.150",3306,"CMMI2PM");
					//Get an instance reference to the DbFacade object
					SqlDB dbf = null;
					dbf = new SqlDB();
					
					String sql = "select permission from employee where username = '" + username + "' and password ='" + password + "'";
					
					ResultSet rs = null;
					rs=dbf.executeQuery(sql);	
					
					logger.info("executeQuery" + sql + "in isUserLogon");			
			
					if (rs.next())
					{
	           			perm = rs.getString("permission");
	           			return true;
	           		} else 
	           		{
	           			return false;
	           		}
			}
			catch (Exception e)   	
			{
				logger.error("Exception in isUserLogon:" + e.getMessage());
				return false;
			}

    }

*/
    /**
     * Login the user.
     * The event is logged if the debug level is >= Constants.DEBUG.
     *
     * @param mapping The ActionMapping used to select this instance
     * @param actionForm The ActionForm bean for this request (if any)
     * @param request The HTTP request we are processing
     * @param response The HTTP response we are creating
     *
     * @exception IOException if an input/output error occurs
     * @exception ServletException if a servlet exception occurs
     */
    public ActionForward perform(ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response)
        throws IOException, ServletException {

        // Obtain username and password from web tier
        String username = ((LogonForm) form).getUsername();
        String password = ((LogonForm) form).getPassword();
        
        ((LogonForm) form).setUsername("");
        ((LogonForm) form).setPassword("");
        
        Employee currUser = new Employee();
        currUser.getUserInforByUserName(username);
        perm = currUser.getPermissions();
       
       if (!password.equals(currUser.getPassword()))
       {
            // credentials don't match
            ActionErrors errors = new ActionErrors();
            errors.add(ActionErrors.GLOBAL_ERROR,
            new ActionError("error.logon.invalid"));
            saveErrors(request,errors);
            // return to input page
            return (new ActionForward(mapping.getInput()));
        }

        // Save our logged-in user in the session,
        // because we use it again later.
       
        HttpSession session = request.getSession();
        session.setAttribute(com.cmmi2pms.common.Constants.USER_KEY, currUser);

        // Log this event, if appropriate
        logger.info("LogonAction: User " + username +" logged on in session: " + session.getId());
        

        // Return success
        if (perm.equals("SA"))
        {        
        	return (mapping.findForward("SA"));
        } else 
        {
        	return (mapping.findForward("ProjectMember"));	
        }      

    }

} // End LogonAction

⌨️ 快捷键说明

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