?? replyaction.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 + -