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

📄 selecttestservlet.java

📁 用java+servlet实现在线考试系统
💻 JAVA
字号:
package com.zte.exam.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Hashtable;
import java.util.List;

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

import com.zte.beans.ExamQuestion;
import com.zte.database.Database;

public class SelectTestServlet extends HttpServlet {

	private static final Object Hashtable = null;
	/**
	 * Constructor of the object.
	 */
	public SelectTestServlet() {
		super();
	}
	int count=0;
	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
       
		request.setCharacterEncoding("gbk");
		String username=request.getParameter("RadioGroup1");
		String intpage = request.getParameter("page");
		String testtype=(String)request.getSession().getAttribute("name"); 
		int sumcount=Integer.parseInt(intpage);
		//request.getSession().setAttribute("intpage",intpage);
		System.out.println("anwser is "+username);
		System.out.println("intpage is "+intpage);
		username=username.substring(0,username.indexOf("."));
		System.out.println(username);
		String id=(String)request.getSession().getAttribute("id");
		System.out.println(id+"-------"+username);
		Database db = new Database();
		List list=(List)request.getSession().getAttribute("list");
		String sql="select selectoption ,quscore from exam_question where qu_id='";
		sql+=id+"'";
		System.out.println(sql+"minah");
		ResultSet rs=db.query(sql);
		ExamQuestion eq= new ExamQuestion();
		try {
			
			while(rs.next())
			{
				String selectoption=rs.getString("selectoption");
				String quscore=rs.getString("quscore");
				int score=Integer.parseInt(quscore);
				request.getSession().setAttribute("quscore",quscore);
				System.out.println("******"+selectoption+"33111111");
				if(sumcount>10)
				{
					response.sendRedirect("student/showfraction.jsp?page="+intpage);
					return;
				}else if(selectoption.equals(username))
				{   
					eq.setSumscore(score);
					eq.setSumcount(1);
					list.add(eq);
					response.sendRedirect("student/starttest.jsp?page="+intpage+"&testtype="+testtype);
				}else 
				{
					eq.setSumscore(0);
					eq.setSumcount(0);
					list.add(eq);
					response.sendRedirect("student/starttest.jsp");
				}
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request,response);
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}

⌨️ 快捷键说明

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