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

📄 voteaction.java

📁 J2EE电子商务系统开发从入门到精通---基于Struts和Hibernate技术实现
💻 JAVA
字号:
/*
 * VoteAction.java
 *
 * Created on 2006年8月19日, 上午7:08
 */

package action.vote;

import dbservice.hibernate.HibernateService;
import form.vote.*;
import javax.servlet.http.*;
import model.hr.hibernate.Department;
import model.hr.hibernate.DepartmentUtil;
import model.hr.hibernate.Employee;
import model.vote.hibernate.*;
import java.util.*;

import org.apache.struts.action.*;
/**
 *
 * @author Administrator
 * @version
 */

public class VoteAction 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 {
        // 从用户Http请求中得到参数employeeid的值,即当前用户的编号
        String employeeId = request.getParameter("employeeid");
        // 从用户Http请求中得到参数themeid的值,即当前议题信息的编号
        String themeId = request.getParameter("themeid");
        
        // 获得页面表单中用户输入的信息
        VoteForm voteForm = (VoteForm)form;
        String choiceId = voteForm.getChoiceId();
        
        // 根据用户所选择的议题选项,向数据库中插入一条投票信息
        boolean isSuccess = ResultUtil.insert(choiceId, employeeId);
        if (isSuccess == false) {
            return new ActionForward(mapping.getInput());
        }
        
        // 根据议题信息的编号,从数据库中读取对应的投票信息
        List list = ResultUtil.getResultByTheme(themeId);
        if (list == null) {
            return new ActionForward(mapping.getInput());
        }
        
        // 获得HttpSession缓存
        HttpSession httpSession = request.getSession();
        // 将投票信息存入缓存
        httpSession.setAttribute("resultbytheme", list); 
        
        // 从数据库读取当前所有的部门信息
        List depList = DepartmentUtil.findAll();
        if (list == null) {
            return new ActionForward(mapping.getInput());
        }
        // 将部门信息存入缓存
        httpSession.setAttribute("departmentlist", depList);
        
        // 根据议题信息编号,从数据库中读取对应议题在各部门中的投票情况
        list = new ArrayList();
        for (int i=0; i<depList.size(); i++) {
            Department dep = (Department)depList.get(i);
            List l = ResultUtil.getResultByDepartment(themeId, dep);
            list.add(l);
        }
        
        // 将部门投票信息存入缓存
        httpSession.setAttribute("resultbydepartment", list);
        
        return mapping.findForward(SUCCESS);        
    }
}

⌨️ 快捷键说明

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