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

📄 adminquestionaction.java

📁 在线考试功能
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.onlinestudy.action.teacher;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.onlinestudy.domain.QuestionType;
import com.onlinestudy.domain.Questions;
import com.onlinestudy.service.QuestionService;

/** 
 * MyEclipse Struts
 * Creation date: 04-04-2009
 * 
 * XDoclet definition:
 * @struts.action parameter="status" validate="true"
 */
public class AdminQuestionAction extends DispatchAction {
	QuestionService questionService;
	
	//增加试题分类
	public ActionForward addQType(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		String name = new String(request.getParameter("name").trim().getBytes("ISO8859-1"),"GBK");
		QuestionType qType = new QuestionType();
		qType.setName(name);
		questionService.addQuestionType(qType);
		request.getRequestDispatcher("showQuestion.do?status=showQType").forward(request, response);
		return null;
	}
	
	//修改试题分类名称
	public ActionForward updateQType(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		int id = Integer.parseInt(request.getParameter("id"));
		String name = new String(request.getParameter("name").trim().getBytes("ISO8859-1"),"GBK");
		QuestionType qType = questionService.SelectQTypeById(id);
		qType.setName(name);
		questionService.updateQuestionType(qType);
		request.getRequestDispatcher("showQuestion.do?status=showQType").forward(request, response);
		return null;
	}
	
	//删除题型
	public ActionForward deleteQType(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		int id = Integer.parseInt(request.getParameter("id"));
		questionService.deleteQuestionType(id);
		request.getRequestDispatcher("showQuestion.do?status=showQType").forward(request, response);
		return null;
	}
	
	//录入试题
	public ActionForward addQuestion(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		int typeId = Integer.parseInt(request.getParameter("typeid"));
		String contents = new String(request.getParameter("content").trim().getBytes("ISO8859-1"),"GBK");
		String rightAnswer = new String(request.getParameter("rightAnswer").trim().getBytes("ISO8859-1"),"GBK");
		
		QuestionType qType = questionService.SelectQTypeById(typeId);
		Questions qt = new Questions();
		qt.setContents(contents);
		qt.setRightAnswer(rightAnswer);
		qt.setType(qType);
		
		questionService.addQuestion(qt);
		request.getRequestDispatcher("showQuestion.do?status=showQuestion&nextpage=1").forward(request, response);
		return null;
	}
	//试题修改
	public ActionForward updateQuestion(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		int id = Integer.parseInt(request.getParameter("id"));
		int typeId = Integer.parseInt(request.getParameter("typeid"));
		String contents = new String(request.getParameter("content").trim().getBytes("ISO8859-1"),"GBK");
		String rightAnswer = new String(request.getParameter("rightAnswer").trim().getBytes("ISO8859-1"),"GBK");
		
		QuestionType qType = questionService.SelectQTypeById(typeId);
		Questions qt = questionService.selectQuestionById(id);
		qt.setContents(contents);
		qt.setRightAnswer(rightAnswer);
		qt.setType(qType);
		
		questionService.updateQuestion(qt);
		request.getRequestDispatcher("showQuestion.do?status=showQuestion&nextpage=1").forward(request, response);
		return null;
	}
	
	public ActionForward deleteQuestion(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		String[]ids = request.getParameterValues("ckb");
		questionService.deleteQuestion(ids);
		request.getRequestDispatcher("showQuestion.do?status=showQuestion&nextpage=1").forward(request, response);
		return null;
	}


	public void setQuestionService(QuestionService questionService) {
		this.questionService = questionService;
	}

}

⌨️ 快捷键说明

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