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

📄 examaction.java

📁 在线考试 考生登陆 查分 管理员管理后台等的 的的的的达到的达到的的的
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package com.eonline.controller;import com.eonline.model.*;import demo.ScoreSessionRemote;import java.util.*;import java.sql.Timestamp;import javax.naming.InitialContext;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionMapping;import org.apache.struts.action.ActionForward;/** * * @author Administrator */public class ExamAction extends org.apache.struts.action.Action {        /* forward name="success" path="" */    private final static String SUCCESS = "success";        /**     * This is the action called from the Struts framework.     * @param mapping The ActionMapping used to select this instance.     * @param form The optional ActionForm bean for this request.     * @param request The HTTP Request we are processing.     * @param response The HTTP Response we are processing.     * @throws java.lang.Exception     * @return     */    @Override    public ActionForward execute(ActionMapping mapping, ActionForm form,            HttpServletRequest request, HttpServletResponse response)            throws Exception {        Euser user=(Euser)request.getSession().getAttribute("userItem");        if(user==null){            return mapping.findForward("welcome");        }        List<Item1> list=new LinkedList();        int totalScore=0;        StringBuffer uanswer=new StringBuffer();    //Store user's all answer by the format ABD,B,空,C,BCD,        StringBuffer sanswer=new StringBuffer();    //Store standard answer by ABD,B,ABC,C,BCD,        HttpSession session=request.getSession();        list=(List<Item1>)session.getAttribute("testList");        for (Item1 item : list) {            String[]  tempUserAnswer = (String[]) request.getParameterValues("Choose"+item.getQID());            String userAnswer="";   //获取该道选择题的用户选择项的字符串            if(tempUserAnswer!=null){                for(String temp:tempUserAnswer){                    if(temp!=null){                        userAnswer+=temp;                    }                }            }            String standAnswer=item.getAnswer().replace(",", "");            System.out.println("userAnswer="+userAnswer);            if ((userAnswer != null)&&(!userAnswer.isEmpty())) {                if (standAnswer.trim().equals(userAnswer.trim())) {                    totalScore += 20;   //caculate scores                }                uanswer.append(userAnswer + ",");            } else {                uanswer.append("空" + ",");            }            sanswer.append(standAnswer.replace(",", "") + ",");        }//end of for         InitialContext ctx = new InitialContext();        ScoreSessionRemote sSvc = (ScoreSessionRemote)ctx.lookup(ScoreSessionRemote.class.getName());        sSvc.ScoreSessionBean(user.getUid());        //ScoreService sSvc=new ScoreService(user.getUid());        //java.text.SimpleDateFormat fmt=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");     //设置时间格式        Timestamp date=new Timestamp(System.currentTimeMillis());   //获取系统时间        Score score=new Score(user.getUid(),date, totalScore, uanswer.toString(), sanswer.toString());        sSvc.addScore(score);   //考分存入数据库        session.setAttribute("score", score);        session.setAttribute("uanswer", uanswer);        session.setAttribute("sanswer", sanswer);        return mapping.findForward("success");    }}

⌨️ 快捷键说明

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