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

📄 questionaction.java

📁 中应用程序的访问权限对Java Web Console 中应用程序的访问权限 成功登录 Web 控制台后,可能无法自动访问在该控制台中注册的所有应用程序。通常,必须安装应用程序,才能让所有的用户在控制
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
  * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package edu.yinhe.mis.control;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

import edu.yinhe.mis.dto.QuestionDTO;
import edu.yinhe.mis.util.DownLoadFile;
import edu.yinhe.mis.vo.QuestionVO;
import edu.yinhe.system.common.AppException;
import edu.yinhe.system.common.ConnectionManager;
import edu.yinhe.system.control.BaseAction;
import edu.yinhe.system.util.PaginationVO;

public class QuestionAction extends BaseAction {
	
	/**
	 * @author 石小军
	 * Creation date:2008-05-04 
	 * @param 增加试题
	 * @return forward 指定成功后转发的页面
	 * 
	 */
	public ActionForward addQuestion(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

		QuestionForm questionForm = (QuestionForm) form;
		QuestionDTO questionDTO = new QuestionDTO();
		ActionForward forward=mapping.findForward("error");

		try {
			BeanUtils.copyProperties(questionDTO, questionForm);
			
			service.setDataSource(getDataSource(request,"mydatasource"));
			Integer m = (Integer) service.create(questionDTO);
			if(m==1){
				forward = mapping.findForward("allSuccess");
			}

		} catch (IllegalAccessException e){
			e.printStackTrace();
		} catch (InvocationTargetException e){
			e.printStackTrace();
		} catch (AppException e){
			e.printStackTrace();
		}

		return forward;
	}
	/**
	 * @author 石小军
	 * Creation date:2008-05-04
	 * @param 根据指定ID查询试题
	 * @return forward 指定成功后转发的页面
	 * 
	 */
	public ActionForward viewQuestion(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

		QuestionForm questionForm = (QuestionForm) form;
		QuestionDTO questionDTO = new QuestionDTO();
		QuestionVO questionVO = new QuestionVO();
		ActionForward forward=mapping.findForward("error");

		try {
			BeanUtils.copyProperties(questionDTO, questionForm);
			service.setDataSource(getDataSource(request,"mydatasource"));
			Integer n = Integer.parseInt(request.getParameter("qID"));
			questionVO = (QuestionVO)service.findById(n);
			if(questionVO != null){
				request.setAttribute("questionVO", questionVO);
				forward = mapping.findForward("viewQuestionSuccess");
			}

		} catch (IllegalAccessException e){
			e.printStackTrace();
		} catch (InvocationTargetException e){
			e.printStackTrace();
		} catch (AppException e){
			e.printStackTrace();
		}

		return forward;
	}
	/**
	 * @author 石小军
	 * Creation date:2008-05-04 
	 * @param  删除试题
	 * @return forward 指定成功后转发的页面
	 * 
	 */
	public ActionForward delQuestion(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

		QuestionForm questionForm = (QuestionForm) form;
		QuestionDTO questionDTO = new QuestionDTO();
		ActionForward forward=mapping.findForward("allSuccess");
		Object[] array = null;
		try {
			BeanUtils.copyProperties(questionDTO, questionForm);
			service.setDataSource(getDataSource(request,"mydatasource"));
			array = request.getParameterValues("check");
			if(array != null&&array.length>0){			
				Integer m = (Integer) service.remove(array);
				if(m==1){
					forward = mapping.findForward("allSuccess");
				}
			}

		} catch (IllegalAccessException e){
			e.printStackTrace();
		} catch (InvocationTargetException e){
			e.printStackTrace();
		} catch (AppException e){
			e.printStackTrace();
		}

		return forward;
	}
	
	/**
	 * @author 石小军
	 * Creation date:2008-05-04
	 * @param  查询所有试题
	 * @return forward 指定成功后转发的页面
	 * 
	 */
	public ActionForward queryQuestion(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		QuestionForm questionForm = (QuestionForm) form;
		QuestionDTO questionDTO = new QuestionDTO();
		PaginationVO paginationVO = new PaginationVO();
		ActionForward forward = mapping.findForward("error");
		Object[] objq = null;
		String currentPage = request.getParameter("currentPage");
		if(currentPage == null||"".equals(currentPage)){
			currentPage = "1";
		}
		try {
			try {
				BeanUtils.copyProperties(questionDTO,questionForm);
				String qid = request.getParameter("qID");
				Integer n=0;
				if(qid!=null&&!"".equals(qid)){
					
					 n = Integer.parseInt(qid);
				}
				questionDTO.setQuestionID(n);
				
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			}
			paginationVO.setCurrentPage(Integer.parseInt(currentPage));
			questionDTO.setRowPerPage(10);
			questionDTO.setCurrentPage(Integer.valueOf(paginationVO.getCurrentPage()));	
			service.setDataSource(getDataSource(request,"mydatasource"));
			objq = (Object[])service.findAll(questionDTO);

			int count = ((Integer)objq[1]).intValue();
			paginationVO.setResultsNumber(count);
			paginationVO.setRowsPerPage(10);
			paginationVO.setAllPages((count/paginationVO.getRowsPerPage())+(count%paginationVO.getRowsPerPage()>0?1:0));
			List qlist = (List)objq[0];
			if(qlist!=null&&qlist.size()!=0){
				request.setAttribute("qlist", qlist);
				request.setAttribute("paginationVO", paginationVO);
				request.setAttribute("questionDTO", questionDTO);
				forward = mapping.findForward("success");
			}
		} catch (AppException e) {
			e.printStackTrace();
		}

		return forward;
	}
	/**
	 * @author 石小军
	 * Creation date:2008-05-04 
	 * @param 根据指定ID查询试题并把该试题的详细信息转发到updateQuestion.jsp
	 * @return forward 指定成功后转发的页面
	 * 
	 */
	public ActionForward lookQuestion(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

		QuestionForm questionForm = (QuestionForm)form;
		QuestionDTO questionDTO = new QuestionDTO();
		QuestionVO questionVO = new QuestionVO();
		ActionForward forward=mapping.findForward("error");

		try {
			BeanUtils.copyProperties(questionDTO, questionForm);
			service.setDataSource(getDataSource(request,"mydatasource"));
			Integer n = Integer.parseInt(request.getParameter("qID"));
			questionVO = (QuestionVO)service.findById(n);
			if(questionVO != null){
				request.setAttribute("questionVO", questionVO);
				forward = mapping.findForward("updateQuestion");
			}

		} catch (IllegalAccessException e){
			e.printStackTrace();
		} catch (InvocationTargetException e){
			e.printStackTrace();
		} catch (AppException e){
			e.printStackTrace();
		}

		return forward;
	}
	/**
	 * @author 石小军
	 * Creation date:2008-05-04 
	 * @param 修改试题
	 * @return forward 指定成功后转发的页面
	 * 
	 */
	public ActionForward updateQuestion(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

		QuestionForm questionForm = (QuestionForm)form;
		QuestionDTO questionDTO = new QuestionDTO();
		QuestionVO questionVO = new QuestionVO();
		ActionForward forward=mapping.findForward("error");

		try {
			BeanUtils.copyProperties(questionDTO, questionForm);

			service.setDataSource(getDataSource(request,"mydatasource"));
			Integer m = (Integer)service.modify(questionDTO);
			if(m == 1){
				forward = mapping.findForward("allSuccess");
			}

		} catch (IllegalAccessException e){
			e.printStackTrace();
		} catch (InvocationTargetException e){
			e.printStackTrace();
		} catch (AppException e){
			e.printStackTrace();
		}

		return forward;
	}
	/**
	 * @author 石小军
	 * Creation date:2008-05-04 
	 * @param 查询难度等级表中的所有信息
	 * @return null(此控制器无需返回值)
	 * 
	 */
	public ActionForward queryDifficultyDegree(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

		//DifficultyDegreeForm difficultyDegreeForm = (DifficultyDegreeForm)form;

		ArrayList list = new ArrayList();
		ActionForward forward=mapping.findForward("error");

		try {
			
			service.setDataSource(getDataSource(request,"mydatasource"));
			list = (ArrayList) service.list();
			if(list != null){
				request.setAttribute("dlist", list);
			}

		} catch (AppException e){
			e.printStackTrace();
		}

		return null;
	}
	/**
	 * @author 石小军
	 * Creation date:2008-05-04 
	 * @param 查询出所有科目名称并封装到olist中
	 * @return forward到相应的页面
	 * 
	 */
	public ActionForward forward(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		QuestionForm questionForm = (QuestionForm) form;
		List list = null;

		ActionForward forward = mapping.findForward("error");
		try {
			Integer n = Integer.parseInt(request.getParameter("n"));
			service.setDataSource(getDataSource(request,"mydatasource"));
			list = (List)service.findAll();
			if(list != null){
				request.setAttribute("olist", list);
				switch(n){
				case 1:
					forward = mapping.findForward("toSingleSelect");
					break;
				case 2:
					forward = mapping.findForward("toMoreSelect");
					break;
				case 3:
					forward = mapping.findForward("toJudge");
					break;
				case 4:
					forward = mapping.findForward("toTianKong");
					break;
				case 5:
					forward = mapping.findForward("toEssayQuestion");
					break;
				}

			}
		} catch (AppException e) {
			e.printStackTrace();
		}
		return forward;

	}
	/**
	 * @author 石小军
	 * Creation date:2008-05-05 
	 * @param 批量上传单选题
	 * @return forward到上传成功页面
	 * @throws IOException 
	 * 
	 */

⌨️ 快捷键说明

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