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

📄 managepollaction.java

📁 近几年来
💻 JAVA
字号:
package tarena.action;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Set;import javax.servlet.ServletContext;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;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.ActionMessage;import org.apache.struts.actions.LookupDispatchAction;import org.hibernate.Session;import tarena.pojo.Poll;import tarena.pojo.PollLine;import tarena.proxy.Business;import tarena.util.ContextUtil;public class ManagePollAction extends LookupDispatchAction {	protected Map getKeyMethodMap() {		Map map = new HashMap();		map.put("info.button.endpoll", "end");		map.put("info.button.deletepoll", "delete");		return map;	}	/**	 * 假设保存调查成功, 则将application作用域的poll对象删除, clientIPMap对象清空, 跳转至调查列表页面, 显示成功信息,	 * 或者显示失败信息	 */	public ActionForward end(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response) {		ServletContext servletContext = request.getSession()				.getServletContext();		int availableNum = 0;		double totalScore = 0.0d;		Poll poll = (Poll) servletContext.getAttribute(ContextUtil.POLL);		Set pollLineSet = poll.getPollLineSet();		for (Iterator it = pollLineSet.iterator(); it.hasNext();) {			PollLine pollLine = (PollLine) it.next();			if (pollLine.getIsValid().equals("y")) {				availableNum++;				totalScore += pollLine.getC1().doubleValue()						+ pollLine.getC2().doubleValue()						+ pollLine.getC3().doubleValue()						+ pollLine.getC4().doubleValue()						+ +pollLine.getC5().doubleValue()						+ pollLine.getC6().doubleValue()						+ pollLine.getC7().doubleValue();			}		}		poll.setAmount(new Integer(poll.getPollLineSet().size()));		poll.setAvailableNum(new Integer(availableNum));		poll.setTotalscore(new Integer((int)totalScore));		poll.setAvgScore(new Double(Math.round(totalScore				/ poll.getAvailableNum().intValue() / 7 * 100) / 100.00));		poll.setStatus("n");		ActionErrors errors = new ActionErrors();		Session session = (Session)request.getAttribute(ContextUtil.SESSION);		if (pollLineSet.size() < 1) {			errors.add("warn.endpoll", new ActionMessage("warn.endpoll"));		} else if (Business.savePoll(session, poll)) {			servletContext.removeAttribute(ContextUtil.POLL);			Map clientIPMap = (Map) servletContext					.getAttribute(ContextUtil.CLIENT_IP_MAP);			clientIPMap.clear();			errors.add("info.endpoll", new ActionMessage("info.endpoll"));		} else {			errors.add("error.endpoll", new ActionMessage("error.endpoll"));		}		saveErrors(request.getSession(), errors);		return mapping.findForward("return");	}	/**	 * 将application作用域的poll对象删除,clientIPMap对象清空, 跳转至调查列表页面	 */	public ActionForward delete(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response) {		ServletContext servletContext = request.getSession()				.getServletContext();		servletContext.removeAttribute(ContextUtil.POLL);		Map clientIPMap = (Map) servletContext				.getAttribute(ContextUtil.CLIENT_IP_MAP);		clientIPMap.clear();		ActionErrors errors = new ActionErrors();				errors.add("info.deletepoll", new ActionMessage("info.deletepoll"));		saveErrors(request.getSession(), errors);				return mapping.findForward("return");	}}

⌨️ 快捷键说明

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