【Java开源代码栏目提醒】:网学会员Java开源代码为您提供VoteAction.java参考,解决您在VoteAction.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);
}
}
上一篇:
VoteAct.java
下一篇:
关于大学英语教学