📄 student_examinationaction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package action;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
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 po.QuestionPO;
import vo.*;
import business.Exam_paperDAO;
/**
* MyEclipse Struts
* Creation date: 04-29-2007
*
* XDoclet definition:
* @struts.action validate="true"
*/
public class student_examinationAction 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) {
//遍历出试题
String submit = (String)request.getParameter("submit");
HttpSession session = request.getSession();
String rkey = (String)session.getAttribute("rkey");//答对题数
String wkey = (String)session.getAttribute("wkey");//答错题数
String examno = (String)session.getAttribute("examno");//题号
QuestionPO qpo = (QuestionPO)session.getAttribute("qpo");//所出的题
ArrayList al = (ArrayList)session.getAttribute("list");
String rightkey = (String)session.getAttribute("rightkey");
String wrongkey = (String)session.getAttribute("wrongkey");
String did = (String)session.getAttribute("did");
String cno = (String)session.getAttribute("cid");
String cid = (String)request.getParameter("cid");
String time = (String)request.getParameter("time1");
QuestionPO qu = (QuestionPO)session.getAttribute("QuestionPO");
QuestionPO quu = null;
ArrayList arraylist = new ArrayList();
overanswerVO overanswer = (overanswerVO)session.getAttribute("overanswer");//答过的题
overanswersVO overanswers = (overanswersVO)session.getAttribute("overanswers");//学生的答案
if(overanswer == null)
{
overanswer = new overanswerVO();
overanswer.setArray(arraylist);
}
if(overanswers == null)
{
overanswers = new overanswersVO();
overanswers.setAl(arraylist);
}
session.setAttribute("time", time);
Exam_paperDAO epdao = new Exam_paperDAO();
if(cno != null)
{
cid = cno;
}
ArrayList array = epdao.findByCid(Integer.parseInt(cid));
int[] sign = new int[20];
if(submit == null || submit.equals("下一题"))
{
if(rkey==null && wkey==null && examno==null && qpo==null)
{
rkey = "0";
wkey = "0";
examno = "1";
rightkey = "0";
wrongkey = "0";
did = "1";
for(int i =0;i<array.size();i++)
{
QuestionPO q = (QuestionPO)array.get(i);
sign[i] = q.getQid();
}
int paperid = (int)(Math.random()*array.size());//随机取题
for(int j = 0;j<array.size();j++)
{
qpo = (QuestionPO)array.get(j);//将此题写入PO中
if(sign[paperid] != -1)//标志位1代表无标志位
{
sign[paperid] = -1;
qpo.setSign(sign);
overanswer.getArray().add(qpo);
session.setAttribute("overanswer",overanswer);//答过的题
session.setAttribute("rkey",rkey);//答对题数
session.setAttribute("wkey",wkey);//答错题数
session.setAttribute("examno",examno);//题号
session.setAttribute("qpo",qpo);//所出的题
session.setAttribute("rightkey",rightkey);
session.setAttribute("wrongkey",wrongkey);
session.setAttribute("wrongkey",wrongkey);
session.setAttribute("cid",cid);
session.setAttribute("did",did);
break;
}
}
}
//第二次
else
{
if(qu != null)
{
quu = qu;
}
else
{
quu = qpo;
}
String single = (String)request.getParameter("single");
if(single.equals(quu.getAnswer()))
{
rightkey = (Integer.parseInt(rightkey)+1)+"";
rkey = (Integer.parseInt(rkey)+1)+"";
session.setAttribute("rkey",rkey);
if(rightkey.equals("3"))
{
did = quu.getDid()+"";
if(did.equals("3"))
{
quu.setDid(3);
}
else
{
did = (quu.getDid()+1)+"";
}
session.setAttribute("did",did);
rightkey = "0";
}
}
else
{
wrongkey = (Integer.parseInt(wrongkey)+1)+"";
wkey = (Integer.parseInt(wkey)+1)+"";
session.setAttribute("wkey",wkey);
if(wrongkey.equals("3"))
{
did = quu.getDid()+"";
if(did.equals("1"))
{
quu.setDid(1);
}
else
{
did = (quu.getDid()-1)+"";
}
session.setAttribute("did",did);
wrongkey = "0";
}
}
//继续选题
sign = qpo.getSign();
int paperid = (int)(Math.random()*array.size());//随机取题
while(true)
{
if(sign[paperid] != -1)//标志位1代表无标志位
{
qu = new Exam_paperDAO().findByID(sign[paperid]);
sign[paperid] = -1;
qpo.setSign(sign);
overanswer.getArray().add(qu);
overanswers.getAl().add(single);
session.setAttribute("list",al);
session.setAttribute("overanswer",overanswer);//答过的题
session.setAttribute("overanswers",overanswers);//学生的答案
session.setAttribute("examno",(Integer.parseInt(examno)+1)+"");//题号
session.setAttribute("rightkey",rightkey);
session.setAttribute("wrongkey",wrongkey);
session.setAttribute("cid",cno);
session.setAttribute("QuestionPO", qu);
break;
}
else
{
paperid = (int)(Math.random()*array.size());//随机取题
}
}
}
return mapping.findForward("ok");//student_examination.jsp
}
else
{
return mapping.findForward("no");//student_submitpaterAction.do
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -