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

📄 titlesystemaction.java

📁 在线考试系统: 这是基于struts和Hibernate的最新技术的在线考试系统.数据库是MySql.能添加课程
💻 JAVA
字号:
package com.zjxy.hibernate.action;


import java.lang.reflect.InvocationTargetException;
import java.util.List;

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



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.actions.DispatchAction;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.zjxy.hibernate.HibernateSessionFactory;
import com.zjxy.hibernate.base.PageDAO;

import com.zjxy.hibernate.base.TitleSystemManager;

import com.zjxy.hibernate.base.TitleManager;

import com.zjxy.hibernate.form.TitleSystemForm;

import com.zjxy.hibernate.model.TitleSystem;
import com.zjxy.hibernate.pagerHelp.Pager;
import com.zjxy.hibernate.pagerHelp.PagerHelp;


public class TitleSystemAction extends DispatchAction{
	
	/**
	 * 题库管理信息一览画面显示
	 * @param actionMapping
	 * @param actionForm
	 * @param httpServletRequest
	 * @param httpServletresponse
	 * @return
	 */
	 public ActionForward display(ActionMapping actionMapping,
             ActionForm actionForm,
             HttpServletRequest httpServletRequest,
             HttpServletResponse httpServletresponse) {
	
		    // 用于输出到页面的记录集合
	        List clInfos = null;
	        String sqlBean = "from com.zjxy.hibernate.model.TitleManage";
	        // 记录总行数
	        int totalRows = 0;
	        TitleManager titleManager = new TitleManager();
	        List list = titleManager.getTitleManageList();
	        totalRows = list.size();
	        PageDAO pageDAO = new PageDAO();

	        // 取得当前表中的总行数

	        // 通过PagerHelper类来获取用于输出到页面的pager对象
	        Pager pager=PagerHelp.getPager(httpServletRequest,totalRows);

	        // 取出从startRow开始的pageSize行记录
	        try {
	            clInfos = pageDAO.findWithPage(pager.getPageSize(), pager.getStartRow(),sqlBean);
	            } catch (Exception ex) {
	                servlet.log(ex.toString());
	         }
	       
	         Integer total = Integer.valueOf(totalRows);
	         //把输出的记录集和pager对象保存到request对象中
	         httpServletRequest.setAttribute("TOTALROWS", total);
	         httpServletRequest.setAttribute("CLINFOS", clInfos);
	         httpServletRequest.setAttribute("PAGER", pager);
	         
         return actionMapping.findForward("display");
      }
	 

	 
		/**
		 * 判断题添加画面初期表示
		 * @param actionMapping
		 * @param actionForm
		 * @param httpServletRequest
		 * @param httpServletresponse
		 * @return
		 */
	 public ActionForward addJudgeDisplay(ActionMapping actionMapping,
       ActionForm actionForm,
       HttpServletRequest httpServletRequest,
       HttpServletResponse httpServletresponse) {
		 return actionMapping.findForward("addJudgeDisplay");
	 }
	 
		/**
		 * 主观题添加画面初期表示
		 * @param actionMapping
		 * @param actionForm
		 * @param httpServletRequest
		 * @param httpServletresponse
		 * @return
		 */
	 public ActionForward addSubjectiveDisplay(ActionMapping actionMapping,
    ActionForm actionForm,
    HttpServletRequest httpServletRequest,
    HttpServletResponse httpServletresponse) {
		 return actionMapping.findForward("addSubjectiveDisplay");
	 }
	 
		/**
		 * 选择题添加画面初期表示
		 * @param actionMapping
		 * @param actionForm
		 * @param httpServletRequest
		 * @param httpServletresponse
		 * @return
		 */
	 public ActionForward addSelectDisplay(ActionMapping actionMapping,
    ActionForm actionForm,
    HttpServletRequest httpServletRequest,
    HttpServletResponse httpServletresponse) {
		 return actionMapping.findForward("addSelectDisplay");
	 }
	 /**
		 * 预览画面初期表示
		 * @param actionMapping
		 * @param actionForm
		 * @param httpServletRequest
		 * @param httpServletresponse
		 * @return
		 */
	 public ActionForward selectDisplay(ActionMapping actionMapping,
 ActionForm actionForm,
 HttpServletRequest httpServletRequest,
 HttpServletResponse httpServletresponse) {
		 String kemuID = "";
		 	 if(httpServletRequest.getParameter("kemuID")!=null){
			 kemuID=httpServletRequest.getParameter("kemuID").toString();
			 
		 }
		 String tikuNO = "";
		 if(httpServletRequest.getParameter("tikuNO")!=null){
			 tikuNO=httpServletRequest.getParameter("tikuNO").toString();
			 
		 }
	     String kemuName = "";
	     TitleSystemManager titleSystemManager = new TitleSystemManager();
	     TitleSystem titleSystem = new TitleSystem();
	     titleSystem.setKemuID(kemuID);
	     titleSystem.setTikuNO(tikuNO);

	    	 kemuName = titleSystemManager.getKemuNameByID(kemuID);
	     
		    // 用于输出到页面的记录集合
	        List clInfos = null;
	        String sqlBean = "from com.zjxy.hibernate.model.TitleSystem where kemuID=? and tikuNO=? ";
	        // 记录总行数
	        int totalRows = 0;
	        TitleSystemManager titleSystemManage = new TitleSystemManager();
	        List list = titleSystemManage.getTitleSystenList();
	        totalRows = list.size();
	        PageDAO pageDAO = new PageDAO();

	        // 取得当前表中的总行数

	        // 通过PagerHelper类来获取用于输出到页面的pager对象
	        Pager pager=PagerHelp.getPager(httpServletRequest,totalRows);

	        // 取出从startRow开始的pageSize行记录
	        try {
	        	clInfos = pageDAO.findWithPage_tikuSearch(pager.getPageSize(), pager.getStartRow(),sqlBean,titleSystem);
	            } catch (Exception ex) {
	                servlet.log(ex.toString());
	         }
	       
	         Integer total = Integer.valueOf(totalRows);
	         //把输出的记录集和pager对象保存到request对象中
	         HttpSession session = httpServletRequest.getSession();
	         session.setAttribute("kemuName", kemuName);
	         session.setAttribute("tikuNO", tikuNO);
	         httpServletRequest.setAttribute("TOTALROWS", total);
	         httpServletRequest.setAttribute("CLINFOS", clInfos);
	         httpServletRequest.setAttribute("PAGER", pager);
	         
		 return actionMapping.findForward("selectDisplay");
	 }
	 
	 public ActionForward searchDisplay(ActionMapping actionMapping,
			 ActionForm actionForm,
			 HttpServletRequest httpServletRequest,
			 HttpServletResponse httpServletresponse) {
					 String kemuID = "";
					 kemuID= httpServletRequest.getParameter("kemuID")==null?"":httpServletRequest.getParameter("kemuID").toString();
					 String tikuNO ="";
					 tikuNO=httpServletRequest.getParameter("tikuNO")==null?"":httpServletRequest.getParameter("tikuNO").toString();
				   
				    // TitleSystemManager titleSystemManager = new TitleSystemManager();
				     TitleSystem titleSystem = new TitleSystem();
				     titleSystem.setKemuID(kemuID);
				     titleSystem.setTikuNO(tikuNO);

				    
				     
					    // 用于输出到页面的记录集合
				        List clInfos = null;
				        String sqlBean = "from com.zjxy.hibernate.model.TitleSystem ";
				        // 记录总行数
				        int totalRows = 0;
				       Session s=HibernateSessionFactory.currentSession();
				        List list = s.createQuery(sqlBean).list();
				        totalRows = list.size();
				        HibernateSessionFactory.closeSession();
				        PageDAO pageDAO = new PageDAO();

				        // 取得当前表中的总行数

				        // 通过PagerHelper类来获取用于输出到页面的pager对象
				        Pager pager=PagerHelp.getPager(httpServletRequest,totalRows);

				        // 取出从startRow开始的pageSize行记录
				        try {
				        	clInfos = pageDAO.findWithPage(pager.getPageSize(), pager.getStartRow(),sqlBean);
				            } catch (Exception ex) {
				                servlet.log(ex.toString());
				         }
				       
				         Integer total = Integer.valueOf(totalRows);
				         //把输出的记录集和pager对象保存到request对象中
				       
				        
				         httpServletRequest.setAttribute("TOTALROWS", total);
				         httpServletRequest.setAttribute("CLINFOS", clInfos);
				         httpServletRequest.setAttribute("PAGER", pager);
				         
					 return actionMapping.findForward("searchDisplay");
	 }


	/**
	 * 题目信息添加
	 * @param actionMapping
	 * @param actionForm
	 * @param request
	 * @param response
	 * @return
	 */
public ActionForward add(ActionMapping actionMapping,
		       ActionForm form,
		       HttpServletRequest request,
		       HttpServletResponse response) {
			//	 System.out.println("=======================================");
				 // 定义TitleSystemForm对象用于获取页面信息
				 TitleSystemForm titleSystemForm = (TitleSystemForm) form;
				 TitleSystem titleSystem = new TitleSystem();
				 TitleSystemManager titleSystemManager = new TitleSystemManager();
				 
				 // 将页面取得的信息设置值到TitleManage JavaBean中
				 // 科目ID
				 titleSystem.setKemuID(titleSystemForm.getKemuID());
				 // 题型
				 titleSystem.setTikuNO(titleSystemForm.getTikuNO());
				 // 题目序号
				 titleSystem.setQuestionNo(titleSystemForm.getQuestionNo());
				 // 题干
				 titleSystem.setQuestion(titleSystemForm.getQuestion());
				 // 答案
				 titleSystem.setAnswer(titleSystemForm.getAnswer());

				 // 调用TitleManager类的addTitleManage方法向数据库添加教师信息
				 titleSystemManager.addTitleSystem(titleSystem);
				 //重定向:页面跳转
				 return actionMapping.findForward("addSuccess");
			 }

/**
 * 题目修改画面初期表示
 * @param actionMapping
 * @param actionForm
 * @param httpServletRequest
 * @param httpServletresponse
 * @return
 */
public ActionForward modifyDisplay(ActionMapping actionMapping,
ActionForm form,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletresponse) {
	
    // 定义AdminForm对象用于获取页面信息
	TitleSystemForm titleSystemForm = (TitleSystemForm) form;
	TitleSystem titleSystem = new TitleSystem();
	TitleSystemManager titleSystemManager = new TitleSystemManager();
	 // 从页面取得要修改数据的sequenceID值
	 int sequenceID = Integer.parseInt(httpServletRequest.getParameter("sequenceID"));
	 // 调用getModifyInfoByID方法取得要修改的数据
	 titleSystem = titleSystemManager.getModifyInfoByID(sequenceID);
	 // 将页面取得的信息设置值到Admin JavaBean中
	 
	 try {
		BeanUtils.copyProperties(titleSystemForm, titleSystem);
	} catch (IllegalAccessException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (InvocationTargetException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
 return actionMapping.findForward("modifyDisplay");
}

/**
 * 题目信息修改
 * @param actionMapping
 * @param actionForm
 * @param request
 * @param response
 * @return
 */
public ActionForward modify(ActionMapping actionMapping,
  ActionForm form,
  HttpServletRequest request,
  HttpServletResponse response) {
	System.out.println("=====dddddddddddddddd");
 // 定义AdminForm对象用于获取页面信息
	TitleSystemForm titleSystemForm = (TitleSystemForm) form;
	String id=request.getParameter("id"); 
	Session s=HibernateSessionFactory.currentSession();
	Transaction t=s.beginTransaction();
	System.out.println("======"+id);
	TitleSystem titleSystem=(TitleSystem)s.get(TitleSystem.class,Integer.valueOf(id));

 // 将页面取得的信息设置值到Admin JavaBean中

 titleSystem.setKemuID(titleSystemForm.getKemuID());
 titleSystem.setTikuNO(titleSystemForm.getTikuNO());
 titleSystem.setQuestionNo(titleSystemForm.getQuestionNo());
 titleSystem.setAnswer(titleSystemForm.getAnswer());
 titleSystem.setQuestion(titleSystemForm.getQuestion());
 s.update(titleSystem);

 t.commit();
 HibernateSessionFactory.closeSession();
	System.out.println("=====dddddddddddddddd="+id);
 return actionMapping.findForward("deleteSuccess");
}

/**
 * 题目信息删除
 * @param actionMapping
 * @param actionForm
 * @param request
 * @param response
 * @return
 */
public ActionForward delete(ActionMapping actionMapping,
 ActionForm form,
 HttpServletRequest request,
 HttpServletResponse response) {
	 System.out.println("=========="+request.getParameter("sequenceID"));
	TitleSystemManager titleSystemManager = new TitleSystemManager();
 // 从页面取得要删除数据的sequenceID值
 int sequenceID = Integer.parseInt(request.getParameter("sequenceID"));
 titleSystemManager.delete(sequenceID);
 System.out.println("==========");
 return actionMapping.findForward("deleteSuccess");
}

}

⌨️ 快捷键说明

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