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

📄 viewquestionaction.java

📁 老外的在线考试
💻 JAVA
字号:
/* * CyberTester - J2EE Web application for creating, delivering and managing tests/exams/surveys.  * Copyright (C) 2004 CyberDemia Research and Services Pty Ltd * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program (see the file COPYING); if not, write to the * Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * * See the COPYING file located in the top-level-directory of * the archive of this program for complete text of license. */package com.cyberdemia.cybertester.testee.test;import javax.servlet.*;import javax.servlet.http.*;import org.apache.struts.Globals;import org.apache.struts.action.*;import org.apache.struts.util.MessageResources;import com.cyberdemia.school.*;import com.cyberdemia.cybertester.*;import java.util.Locale;import java.util.logging.*;/** *  * ViewQuestionAction is a Struts action to load the data of a question * for the question review page. *   * @version $Revision: 1.2 $ at $Date: 2004/05/04 17:47:36 $ by $Author: alexycyap $ * @author Alexander Yap */public final class ViewQuestionAction extends AbstractUserAction{	protected ActionForward doPerform(		ActionMapping mapping, ActionForm form,		HttpServletRequest request, HttpServletResponse response,		HttpSession session) throws Exception		{		performGetQuestionView(request, response, session, getSessionLocale(session));		return mapping.findForward(Constants.SUCCESS);	}		public static class FormattedChoice	{		FormattedChoice(boolean correct, String text)		{			m_correct = correct;			m_text = text;		}			public boolean isCorrect()		{			return m_correct;		}			public void setCorrect(boolean correct)		{			m_correct = correct;		}			public String getText()		{			return m_text;		}			private String m_text;		private boolean m_correct;	}	public static void performGetQuestionView(HttpServletRequest request, HttpServletResponse response,			HttpSession session, Locale userLocale) throws Exception	{		Logger logger = CyberTesterUtils.getLogger();		Integer quesId = CyberTesterUtils.getIntegerParameterOrRequestAttribute(request, Constants.QUESTION_ID_KEY);		if (quesId==null)		{			// if not specified as parameter, check if it is already a session attribute             quesId = (Integer)session.getAttribute( Constants.QUESTION_ID_KEY );		}				if (quesId==null)				throw new ServletException("Missing parameter and session attribute "+Constants.QUESTION_ID_KEY);        MessageResources resources = (MessageResources)request.getAttribute( Globals.MESSAGES_KEY );		QuestionData ques = null;		String typeStr = null;		FormattedChoice[] formattedChoices = null;		try		{			QuestionManagerHome qMgrHome = CyberTesterUtils.getQuestionManagerHome();			QuestionManager quesMgr = (QuestionManager)qMgrHome.create();			ques = quesMgr.getQuestionData(quesId);			// Additional request attr to present more info to the JSP page			if (ques.isSingleChoiceType())			{				typeStr = resources.getMessage(userLocale, "label.quesview.type.singleChoice");				String[] answerChoices = ques.getAnswerChoices();				formattedChoices = new FormattedChoice[answerChoices.length];				int correctIdx = Integer.parseInt(ques.getAnswer());				for (int a=0; a<answerChoices.length; a++)				{					formattedChoices[a] = new FormattedChoice( (a==correctIdx), answerChoices[a] );				}			}			else if (ques.isMultipleChoiceType())			{				typeStr = resources.getMessage(userLocale, "label.quesview.type.multipleChoices");				String[] answerChoices = ques.getAnswerChoices();				formattedChoices = new FormattedChoice[answerChoices.length];				for (int a=0; a<answerChoices.length; a++)				{					formattedChoices[a] = new FormattedChoice( false, answerChoices[a] );				}				String[] correctIndices = ques.getAnswer().split(",");				for (int i=0; i<correctIndices.length; i++)				{					formattedChoices[ Integer.parseInt(correctIndices[i]) ].setCorrect( true );				}			}			else if (ques.isKeywordsType())			{				typeStr = resources.getMessage(userLocale, "label.quesview.type.keywords");			}		}		catch (Exception ex)		{			logger.log( Level.SEVERE, "Error getting Question data", ex);			throw ex;		}		request.setAttribute(Constants.QUESTION_DATA_KEY, ques );		request.setAttribute("typeStr", typeStr);		request.setAttribute("formattedChoices", formattedChoices);	}	}

⌨️ 快捷键说明

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