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

📄 replyaction.java

📁 本系统是在线考试系统
💻 JAVA
字号:
package org.yeeku.action;

import org.apache.struts.action.*;
import org.apache.struts.validator.DynaValidatorForm;
import javax.servlet.http.*;
import java.util.*;

import org.yeeku.action.base.BaseAction;
import org.yeeku.model.Question;
/**
 * @author  yeeku.H.lee kongyeeku@163.com
 * @version  1.0
 * <br>Copyright (C), 2005-2008, yeeku.H.Lee
 * <br>This program is protected by copyright laws.
 * <br>Program Name:
 * <br>Date: 
 */
public class ReplyAction extends BaseAction
{
	public ActionForward execute(ActionMapping mapping,ActionForm form,
		HttpServletRequest request, HttpServletResponse response)throws Exception
	{
		HttpSession session = request.getSession(false);
		Map<String , Integer> replyMap = null;
		if( (replyMap = (Map)session.getAttribute("replyMap")) == null )
		{
			replyMap = new HashMap<String , Integer>();
		}
		DynaValidatorForm replyForm = (DynaValidatorForm)form;
		String questionId = (String)replyForm.get("id");
		String[] options = (String[])replyForm.get("options");

		Question question = examService.getQuestionById(Integer.parseInt(questionId));
		//将回答试题的情况放入一个Map中,答对放该题得分
		if ( Arrays.equals(options , question.getSelectOption().split(":") ) )
		{
			replyMap.put(questionId , Integer.parseInt(question.getQuScore()));
		}
		//答错放0分
		else
		{
			replyMap.put(questionId , 0);
		}
		session.setAttribute("replyMap" , replyMap);
		List<Integer> alreadys = new ArrayList<Integer>();
		int questionIndex = 1;
		for (String replyId : replyMap.keySet())
		{
			alreadys.add(Integer.parseInt(replyId));
			questionIndex++;
		}
		if (questionIndex > 10)
		{
			return mapping.findForward("finish");
		}		

		int typeId = (Integer)session.getAttribute("typeId");
		Question nextQuestion = examService.getNextQuestion(alreadys , typeId);
		request.setAttribute("question" , nextQuestion);
		List<String> nextOptions = new ArrayList<String>();
		for (String option : nextQuestion.getQuAnswer().split(":") )
		{
			nextOptions.add(option);
		}
		request.setAttribute("questionIndex" , questionIndex);
		request.setAttribute("qustionOption" , nextOptions);
		return mapping.findForward("success");
	}
}

⌨️ 快捷键说明

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