stsecondmainaction.java

来自「这是一个可以让学生选择自己喜欢的课题」· Java 代码 · 共 223 行

JAVA
223
字号
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.yourcompany.struts.action;

import java.util.List;

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

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import allBeans.StZhiyuan;
import allBeans.Teachers;
import allBeans.Tittles;
import allDAOFactory.IFirstStudentTittleDAO;
import allDAOFactory.ILastStudentTittleDAO;
import allDAOFactory.ITeacherDAO;
import allDAOFactory.ITittleDAO;

/** 
 * MyEclipse Struts
 * Creation date: 08-01-2008
 * 
 * XDoclet definition:
 * @struts.action validate="true"
 */
public class StsecondmainAction extends Action {
	/*
	 * Generated Methods
	 */

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub

		String stid=(String)request.getSession().getAttribute("userID"); //得到学生的ID
		if(stid==null)
			return mapping.findForward("tologinst");
		
		String loginkey=request.getParameter("loginkey");
		String tm=(String)request.getSession().getAttribute("tm");
		
		if(loginkey.equals("changepsw"))
		{
			return mapping.findForward("tostchangepsw");
		}
		else if(loginkey.equals("thname"))
		{
			String thid=request.getParameter("thid");
			ITeacherDAO thdao=new ITeacherDAO();
			Teachers teacher=thdao.thget(thid);
			if(teacher!=null)
			{
			  request.setAttribute("teacher", teacher);
			  return mapping.findForward("tostteacherinfo");
			}
			else
				return null;
		}
		else if(loginkey.equals("tittle"))
		{
			String thid=request.getParameter("thid");
			ITeacherDAO thdao=new ITeacherDAO();
			Teachers teacher=thdao.thget(thid);
			request.setAttribute("thname", teacher.getThName()); //根据老师的ID得到老师的名字
			
			ITittleDAO tidao=new ITittleDAO();
			List list=tidao.tigetbythid(thid);
			request.setAttribute("tilist", list);   //根据老师的ID得到这个老师的所有题目列表
			
			if(request.getSession().getAttribute("thidinsession")!=null)
				request.getSession().removeAttribute("thidinsession");  
			request.getSession().setAttribute("thidinsession", thid);    //将要显示的教师题目的教师ID保存于Session中
			
			return mapping.findForward("tosttittlelist");
		}
		else if(loginkey.equals("out"))
		{
			request.getSession().removeAttribute("userID");
			request.getSession().removeAttribute("st_name");
			request.getSession().removeAttribute("tm");
			return mapping.findForward("tologinst");
		}
		else if(loginkey.equals("help"))
		{
			return mapping.findForward("tosthelp");
		}
		else if(loginkey.equals("backtomain"))
		{
			if(tm.equals("1"))
			{
				IFirstStudentTittleDAO fstdao=new IFirstStudentTittleDAO();
				StZhiyuan stzhiyuanone=fstdao.fstget(stid,"1");
				StZhiyuan stzhiyuantwo=fstdao.fstget(stid,"2");
				StZhiyuan stzhiyuanthree=fstdao.fstget(stid,"3");
				request.setAttribute("stzhiyuanone", stzhiyuanone);
				request.setAttribute("stzhiyuantwo", stzhiyuantwo);
				request.setAttribute("stzhiyuanthree", stzhiyuanthree);
				return mapping.findForward("tostfirstmain");
			}
			else if(tm.equals("2"))
			{
				ILastStudentTittleDAO lstdao=new ILastStudentTittleDAO();
				StZhiyuan stzhiyuan=lstdao.lstgetzhiyuan(stid);
				request.setAttribute("stzhiyuan", stzhiyuan);
				if(stzhiyuan==null)
				{
					request.setAttribute("prior", "4");
				}
				else
				{
					ITittleDAO tidao=new ITittleDAO();
					String timemo=tidao.tiget(stzhiyuan.getTiid()).getTiMemo();
					request.setAttribute("timemo", timemo);
					request.setAttribute("prior", stzhiyuan.getPrior());
				}
				return mapping.findForward("tostsecondmain");
			}
			else if(tm.equals("3"))
			{
				ILastStudentTittleDAO lstdao=new ILastStudentTittleDAO();
				StZhiyuan stzhiyuan=lstdao.lstgetzhiyuan(stid);
				request.setAttribute("stzhiyuan", stzhiyuan);
				if(stzhiyuan!=null)
				{
				  ITittleDAO tidao=new ITittleDAO();
				  String timemo=tidao.tiget(stzhiyuan.getTiid()).getTiMemo();
				  request.setAttribute("timemo", timemo);
				}
				return mapping.findForward("tostlookmain");
			}
			else
			{
				request.removeAttribute("userID");
				request.removeAttribute("st_name");
				request.removeAttribute("tm");
				return mapping.findForward("tologinst");
			}
		}
		else if(loginkey.equals("backtoteacher"))
		{
			if(request.getSession().getAttribute("thidinsession")!=null)
				request.getSession().removeAttribute("thidinsession");
			ITeacherDAO thdao=new ITeacherDAO();
			List list=thdao.thget();
			request.setAttribute("thlist", list);
			return mapping.findForward("tostteacherslist");
		}
		else if(loginkey.equals("edit"))
		{
			ILastStudentTittleDAO lstdao=new ILastStudentTittleDAO();
			StZhiyuan zhiyuan =lstdao.lstgetzhiyuan(stid);
			request.setAttribute("fiid", "0"); //给编辑页面的fiid赋值,但是用不着,只是为了保持一致
			request.setAttribute("tiid", String.valueOf(zhiyuan.getTiid()));
			request.setAttribute("tiname", zhiyuan.getTiname());
			request.setAttribute("thname", zhiyuan.getThname());
			request.setAttribute("word", zhiyuan.getWord());
			return mapping.findForward("tostedit");
		}
		else if(loginkey.equals("select"))
		{
			if(tm.equals("1"))
			{
				String prior=request.getParameter("fi_prior");
				if(request.getSession().getAttribute("priorinsession")!=null)
					request.getSession().removeAttribute("priorinsession");
				request.getSession().setAttribute("priorinsession", prior);
			}
			ITeacherDAO thdao=new ITeacherDAO();
			List list=thdao.thget();
			request.setAttribute("thlist", list);
			return mapping.findForward("tostteacherslist");
		}
		else if(loginkey.equals("delete"))
		{
			ILastStudentTittleDAO lstdao=new ILastStudentTittleDAO();
			StZhiyuan zhiyuan =lstdao.lstgetzhiyuan(stid);
			lstdao.lstdelete(stid);
			//将题目表中题目被选人数置为0
			Integer tiid=zhiyuan.getTiid();
			ITittleDAO tidao=new ITittleDAO();
			Tittles ti=tidao.tiget(tiid);
			ti.setTiStsum(0);
			tidao.tiupdate(ti);
			//得到stsecondmain界面的信息
		    lstdao=new ILastStudentTittleDAO();
			StZhiyuan stzhiyuan=lstdao.lstgetzhiyuan(stid);
			request.setAttribute("stzhiyuan", stzhiyuan);
			if(stzhiyuan==null)
			{
				request.setAttribute("prior", "4");
			}
			else
			{
				tidao=new ITittleDAO();
				String timemo=tidao.tiget(stzhiyuan.getTiid()).getTiMemo();
				request.setAttribute("timemo", timemo);
				request.setAttribute("prior", stzhiyuan.getPrior());
			}
			return mapping.findForward("tostsecondmain");
		}
		else
		{
			request.removeAttribute("userID");
			request.removeAttribute("st_name");
			request.removeAttribute("tm");
			return mapping.findForward("tologinst");
		}
	}
}

⌨️ 快捷键说明

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