Online Examination System Using Applet

Source: Internet
Author: User

This school's experiment is a teaching website. When doing this, we tried to use Java applet to implement an online examination system. the reason is that, although the download speed of the applet is relatively slow, once the download speed is complete, there will be a great degree of freedom during the question preparation period, and the performance of the client is stronger. on the server side, we use Java Servlet. Each time an applet requests a servlet, the servlet randomly selects several questions and answers from the database as objects and then sends them to the applet, the applet receives and displays it to the user.

Code of the question for receiving requests from the Applet:
Private arraylist setquestions (){
Arraylist temp = new arraylist ();
Try {
// Obtain the URL
URL url = new URL (getcodebase (), "/dbeducation/testservlet ");
Urlconnection con = URL. openconnection ();
Con. setusecaches (false );
Inputstream in = con. getinputstream ();
Objectinputstream objstream;
Objstream = new objectinputstream (in );
Temp = (arraylist) objstream. readobject ();
Objlength = temp. Size ();

System. Out. println ("OK ");
} Catch (exception e ){

} Return temp;
}

The servlet side selects the question to send the Code:
Protected void doget (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {
Connection con;
Preparedstatement STM;
Resultset RS;
// Printwriter out;
String SQL;
Int ID [] = new int [200]; // an array used to store ID numbers of the type.
Int temp = 0;
Arraylist all = new arraylist ();
Response. setcontenttype ("text/html; charset = gb2312 ");
// Out = response. getwriter ();
Try {
Con = new contactsql (). getcon ();
SQL = "select ID from testlibkind ";
STM = con. preparestatement (SQL );
Rs00000000.exe cutequery (); // obtain all types of idnumbers for the test question
While (Rs. Next ()){
Id [temp] = Rs. getint (1); // obtain the ID number
Temp ++;
}

For (INT I = 0; I <ID. length; I ++ ){
SQL = "select question, answer, a, B, c, d from testlib where KID =? Order by rand () limit 3 "; // obtain the questions and answers of each type of exercise at random.
STM = con. preparestatement (SQL );
STM. setstring (1, "" + id [I]);
Rs00000000.exe cutequery ();
While (Rs. Next ()){
Arraylist v = new arraylist ();
V. Add (Rs. getstring ("Question"); // obtain the problem
V. Add (Rs. getstring ("Answer"); // obtain the answer
V. Add (Rs. getstring (""));
V. Add (Rs. getstring ("B "));
V. Add (Rs. getstring ("C "));
V. Add (Rs. getstring ("D "));
All. Add (v );
}

}

Outputstream out1; // send the arraylist object to the Applet
Objectoutputstream objstream;
Out1 = response. getoutputstream ();
Objstream = new objectoutputstream (out1 );
Objstream. writeobject (all );
Rs. Close ();
STM. Close ();
Con. Close ();

Return;


} Catch (exception e ){
// Out. println (E. getmessage ());
System. Out. println (E );
}
 
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.