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

📄 loginaction.java

📁 J2EE电子商务系统开发从入门到精通---基于Struts和Hibernate技术实现
💻 JAVA
字号:
/*
 * LoginAction.java
 *
 * Created on 2006年5月5日, 下午3:52
 */

package action;

import org.apache.commons.beanutils.BeanUtils;
import form.LoginActionForm;
import dbservice.hibernate.HibernateService;
import model.hr.hibernate.*;
import java.util.List;

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

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMessage;

import net.sf.hibernate.*;
/**
 *
 * @author Administrator
 * @version
 */

public class LoginAction extends Action {
    
    /* forward name="success" path="" */
    private final static String SUCCESS = "success";
    
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    public ActionForward execute(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        String id = null;
        String pwd = null;
        
        if (form != null) {
            id = ((LoginActionForm)form).getId();
            pwd = ((LoginActionForm)form).getPwd();
        }
        HttpSession httpSession = request.getSession();
        ActionForward actionForward = null;
        List list = HibernateService.execQuery("from Employee where id=" + id + " and pwd=" + pwd);
        if (list == null || list.size() == 0) {
            ActionErrors errors = new ActionErrors();
            errors.add("valid", new ActionMessage("errors.login.id.pwd.valid"));
            this.saveErrors(request, errors);
            actionForward = new ActionForward(mapping.getInput());
        }
        else {
            httpSession.setAttribute("employee", (Employee)list.get(0));
            actionForward = mapping.findForward("success");
        }
//        Employee employee = new Employee();
//        employee.setId("1001");
//        Power power = new Power();
//        power.setId(Byte.valueOf("5"));
//        employee.setPower(power);
//        httpSession.setAttribute("employee", employee);
//        actionForward = mapping.findForward("success");
        
        return actionForward;
    }
}

⌨️ 快捷键说明

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