www.pudn.com > exam.rar > ControlExam.java


package kaoshi.monitor.action; 
 
import java.io.*; 
import java.util.*; 
import javax.servlet.http.*; 
import javax.servlet.*; 
import org.apache.struts.action.*; 
import org.apache.struts.actions.DispatchAction; 
import kaoshi.bean.*; 
 
public class ControlExam extends DispatchAction { 
	//清退考生 
	public ActionForward remove( 
        ActionMapping mapping, 
        ActionForm form, 
        HttpServletRequest request, 
        HttpServletResponse response) 
        	throws Exception  
	{ 
		String sid = request.getParameter("sid"); 
        ServletContext application = request.getSession().getServletContext(); 
        ExamHall kaochang = (ExamHall)application.getAttribute("kaochang"); 
        kaochang.remove(sid); 
		return mapping.findForward("flush"); 
	} 
	//向所有人发放试卷 
	public ActionForward permitAll( 
        ActionMapping mapping, 
        ActionForm form, 
        HttpServletRequest request, 
        HttpServletResponse response) 
        	throws Exception  
    { 
		ServletContext application = request.getSession().getServletContext(); 
        ExamHall kaochang = (ExamHall)application.getAttribute("kaochang"); 
        kaochang.permitAll(); 
		return mapping.findForward("flush"); 
	} 
	//向某个人发放试卷 
	public ActionForward permitExam( 
        ActionMapping mapping, 
        ActionForm form, 
        HttpServletRequest request, 
        HttpServletResponse response) 
        	throws Exception  
    {	 
    	String sid = request.getParameter("sid"); 
		ServletContext application = request.getSession().getServletContext(); 
        ExamHall kaochang = (ExamHall)application.getAttribute("kaochang"); 
        kaochang.permitExam(sid); 
		return mapping.findForward("flush"); 
	} 
	//保存成绩单 
	public ActionForward saveScores( 
        ActionMapping mapping, 
        ActionForm form, 
        HttpServletRequest request, 
        HttpServletResponse response) 
        	throws Exception  
    { 
		ServletContext application = request.getSession().getServletContext(); 
        ExamHall kaochang = (ExamHall)application.getAttribute("kaochang"); 
        Iterator ir = kaochang.getRecords().iterator(); 
 
        String filePath = application.getRealPath("/WEB-INF/result/scoreSheet"); 
        FileWriter fw = new FileWriter(filePath); 
        fw.write("考号\t姓名\t客观题成绩\n"); 
        while (ir.hasNext()) { 
        	Record r = (Record)ir.next(); 
        	fw.write(r.getSid()+"\t"+r.getNm()+"\t"+r.getSelectTypeScore()+"\n"); 
        } 
        fw.close();         
		return mapping.findForward("endTip"); 
	} 
	 
}