Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
DESIGN AND DEVELOPMENT OF ON-LINE MULTIPLE-CHOICE EXAMINATION SYSTEM A PROJECT SUBMITTED TO THE INSTITUTE OF INFORr"'1ATION AND COMMUNICATION TECHONOLOGY, BUET, IN PARTIAL FULFILMENT OF THE REQUIREMENT FOR THE DEGREE OF POST GRADUATE DIPLOMA IN INFROMATION TECHNOLOGY. By Bisnu Pada Biswas Student #DF0131007 Ahmad Raihan Shahidullah Student #DF0131008 Md. Soheb Ahmed Student #DF0131018 .~~.(-~~ /..~~~ ~I:':"_:"' ""Y. ~.$'. G] t~2$ ,.~~ Under the supervision of ~0<"~~ ~.-1':~5"-/~ j 9*~ ,l}'"',- __ Professor Dr. S.M. Lutful Kabir '~,",f\, ~~ 1111111111111111111111111111111111 #S7323# INSTITUTE OF INFORMATION AND COMMUNICATION TECHI'JOLOGY, BUET OCTOBER, 2002 CERTIFICATE This is to certify that this work has been done by us and it has not been submitted elsewhere for the award of any degree or diploma. Countersig ned Signature of the students Dr S. . utful Kabir Supervisor Professor and Director IICT,BUET,Dhaka-1000 Bangladesh Bisnu Pada Biswas Student #DF0131007 Ahmad Raihan Shahidullah Student #DF0131008 ~ Md. Soheb Ahmed Student #DF0131018 ACKNOWLEDGEMENT We want to thank almighty Allah, to whom all praises belong. Almighty gives us capability, knowledge and patience; those we use for achieving goal. We worked for this project under the supervision of our respected Professor Dr. S.M. Lutful Kabir. We are grateful for his constant guidance, suggestion and invaluable assistance. He assisted us by giving his valuable time throughout the project work. His encouragement and motivation helped us to complete our task. We also want to give thanks to every person who helped us with their valuable suggestions and assistances. Contents Volume - I 1. Introduction 1.1 In GeneraL 1.2 Prevailing 1.3 Main features 1.4 Project Paper Layout... 2. Development 1 On-Line Examination 2 2 Methodology and Database 2.3 Imp Iem entati 3. Database of this development... 1 Background 2.1 Development 2.2 Software System 011 Used Pia n .4 4 5 Design 3.1 Description of the Database Developed...................... 7 3.2 Data Used for the development 8 4. Software Design 4.1 Description of the Software Developed...................... 9 4.2 Software Testi n9 14 4.3 Softwa re Custo m iza ti 0 n.......................................... 15 4.4 Getti ng Hel p............................................................... 16 5. Hardware Requirements 5.1 Basic Hardw are l7 5.2 Netwo rk Envi ro nmen t. 18 5.3 T rou bl es hooti n9............................................................. 21 6. Installation 6.1 Oracl e............ 22 6.2 Tomcat... 22 6.3 Softwa re.......................................................................... 22 7. Conclusion and Further Development 7.1 Con cIusion 25 7.2 Fu rther work......... 25 References Append ix 27 :..... 28 Volume - II 1. Mod u Ie 1............................................................................ 1 2. Mod uIe 2........................................................................ 8 3. Mod u Ie 3............................................................................ 20 4. Mod u Ie 4........................................................................... 34 VOLUME - I Chapter 1 Introduction 1.1 In general Examination knowledge is a means and potentials for for evaluating both type student's abilities, of education, formal or informal. Traditional paper based examination is a little bit obsolete in today's world. Recent trend is toward online examination systems. Development in Technologies especially in the field of communications has intensified advantages accessibility, the trend. Online examination over paper based examination simplicity, record manipulation security, system in the rapid evaluation, has many field of global standardization, and warehousing and even it is possible for a examinee to complete the examination from home. 1.2 Prevailing On-Line Examination System Formal and informal academic institutions in many countries are now using their own customized software to take on line examinations. A good example of on-line examination system may be the examinations taken by Cisco Networking Academy. Students need to log into the academy examinations After authentication, students server using ID and password. get chance to give any number of examinations from available. All scores along with given answers are stored in Cisco System's central server. Students get the opportunities to view their scores anytime by logging into that server. Some other on-line examination systems are examinations Prometric, ETS etc. In our country we don't have taken by VUE, many institutions those offer such examination facilities. Many of them have resources 2 but are reluctant to provide such facilities. Cause of this reluctance may be from: .,. Inertia and familiarity with the old system .,. Unawareness of the recent trend y Resource limitation and reluctances to invest in the new system y Informal education and computer based education is not wellliked in our country y Undeveloped communication infrastructure 1.3 Main features of this development y Software has been developed in Java, so it is fully platform independent y Oracle has been used as database server. It is as adaptable highly secured, flexible and pioneer of it's kind y Tomcat has been used as web server. It is as adaptable, highly flexible, widely used to handle Java Servlets and JSP. y Software can be used both in stand alone machine or in network environment 1.4 Project paper Layout Project volume-I paper has been divided and volume-II. into two volumes namely Volume-I contains detailed descriptions of project development, design, and implementation whereas volume-II contains the source code of the developed software. Volume-I comprised of seven chapters. Brief descriptions of each chapter are given below: y Chapter 1 gives an introduction system, benefits over traditional to the on-line examination paper based examination 3 and problems in our country's respect. It also includes the main features of the developed software. ,. Chapter 2 describes different aspects considered and followed while developing the software. It also describes various software and database servers those have been used while testing the software. A brief description on how the software could be implemented is also discussed. ,. Chapter 3 deals with the database objects those have been created for successful implementation of the developed software. Some examples of the objects with inserted data have also been shown. ,. Chapter 4 describes major features outcomes when tested in different requirements of the software environment. and Necessary needed to customize the software and related information sources have been discussed. ,. Chapter 5 describes basic hardware resources necessary both for server side and client side machines. Equipment required to implement the software in networking environment has also been discussed. A short description on possible problems and solutions which may help users is also discussed in this chapter. ,. Chapter 6 describes installation procedure of the developed software along with installation of other necessary software. ,. Chapter 7 describes limitations, possibilities to overcome the limitations and further development of the software. 4 Chapter 2 Development Background 2.1 Development Methodology During development of the software following key points were continuously focused and monitored r Platform independency r Security r Optimum flexibility r User friendliness r Reliability r Simplicity r Versatility r Maintainability 2.2 Software and Database Used Java has been used as the programming language in developing the software. Some other languages like Visual Basic, Visual C++ may also be used to do the same task. Due to Java's robust flexibility, it was selected to develop the software. Unique feature that makes Java the best choice is its platform independency. Java Servlet technology has been used extensively to make this web based software. Scripting la'nguages namely VBScript, Javascript, PHP, ASP may also be used to generate web pages. But Servlet supports nearly all features of Java additionally, Servlet generates html pages dynamically. Tomcat has been used to handle the Servlets and to handle desired web pages dynamically. Tomcat itself has been developed , 5 using Java, so it is also platform independent. Moreover, Tomcat has the ability to handle Servlet which other web servers like lIS, Apache don't have. Developed software has been tested with Tomcat 3.1Ml and Tomcat 3.3.1. Oracle8i, Oracle9i, MySQL and Microsoft Access database server have been tested and used with this software. servers were tested with this software Different to ensure that database developed software would be a versatile one. 2.3 Implementation plan First consideration was to make the web based software platform independent, so java was chosen as the language to develop it. As html page generation was felt essential it was decided to use some html generating technique namely PHP, JSP, Jservlet etc. Java Servlet technology has the potential of using full capabilities of java langulage and it is able to generate html pages dynamically, so it was chosen. Decision was made to make the developed software database independent. But for initial development purpose Microsoft access Database was chosen because of its simplicity. Total task was broken into following modules: ,. Module 1: To develop and test codes necessary for creating database tables ,. Module 2: To develop and test codes necessary for iDserting and manipulating students information in created tables ,. Module 3: To develop and test codes for insertion and manipulation questions in created tables ,. Module 4: To develop and test codes for giving and evaluating examinations 6 Decision was made to maintain module's independency, so that developed software can be customized easily later. After successful completion and testing of each module with Access database, the modules were combined and successfully tested. Then it was decided to test the software with MySQL and that test was also successful. At last, effort was given to transform the whole system to work with Oracle, as Oracle is the most powerful database server. It was done successfully and now the software is working fine with Oracle8i/9i. , 7 Chapter 3 Database Design 3.1 Description of the Database Developed For simplicity, three types of tables have been designed namely Student table, Teacher table and Exam tables and no relationship has been created between the tables. Brief description of the tables are given below: , Teacher Table - it has two columns (ID, Exams) holding values for Course ID and Number of Examinations will be taken for the course. ID - VARCHAR2(15) and PRIMARYKEY Exams - NUMBER(4) , Student Table - it has columns (ID, Name, Examl, , , Examn) holding Number, Student students for values Name, each for Student Examination examination Identification scores (No. Exam2 of of every examinations mentioned in the Teacher table's Exams column) ID - VARCHAR2(15) and PRIMARY KEY Name - VARCHAR2(30) and NOT NULL Examl, , , Examn - NUMBER(4) Exam Table - n number of tables will be created (n=No. of examinations mentioned in the Teacher table's Exams column) with columns (No, Quest, Ansl, Ans2, Ans3, Ans4, Correct) Answerl, holding values Answer2, for Answer3, Question number, Answer4, Correct number for each question. No - NUMBER(4), UNIQUE_NUMBER and NOT NULL Question, Answer 8 Quest - VARCHAR2(200) Ans1 - VARCHAR2(50) Ans2 - VARCHAR2(50) Ans3 - VARCHAR2(50) Ans4 - VARCHAR2(50) Correct - VARCHAR2(5) 3.2 Data Used for the Development These sets of example data for the three tables are shown below: Teacher table: ID Exams IICT -5133 4 Exam1 table: Ans2 Ans3 Ans4 Correct 3 4 5 6 3 5*7=7 20 35 30 45 2 10-4=7 3 4 5 6 4 NO Quest Ans1 1 2+3=7 2 3 I Student table: ID Name Exam1 Exam2 Examn-1 Examn DF0131007 Bishnu 10 7 8 12 DF01310017 Karim 6 8 8 10 DF01310025 Dipta 6 8 8 10 9 Chapter 4 Software Design 4.1 Description of the Software Developed Developed software is web based On-Line Multiple Choice Examination System software. User's request from web browser will be caught and processed by servlets. Connection with the database for authentication should also be handled by servlets. According to user's need servlet will generate and send necessary web pages to users web browser. , Tables (Teacher table, E,xaml, Exam2, , Examn tables, and Student table) can be created automatically using the following page for inserting information 1'1 •••• "nln ('olln. II> (S'''''&I r---Ir,--$._1 ,,- ----_.,._---_ ...--_.-- --- 10 Students registration can be done by using the following page 1~1:"IIz:e:::t/Z;dt.il:!l:l..c::I':Z:\:::!!II.I:.:i::'_C~:.lIHll:j ~I::.illZ:iI:"::::.i::- •__ ._."~II_I!II_ 1_.J:-.rJ«t .• -,\, • 'u :fl, C11 '1lse""h !Ill!1l:!!l!~!I_~~miKli_:::.!::!_!lI:!_il'.;::iii' ••••::I1;;"",!!y!:~~:;;r;{!.f.i CiJ~~"'t...l}'~. \,1! ~~.J ~ . ~ ~ oR 1~~;riJi.tlDI"";_'~I-, •• ;_j;,;;~dl . m _. . .1 3-~Go-!Uft.ooj .:J l'l"'ue EllIff Slud"111 Nalllf' (5Irl"C" 1"''''''='''.------Pi •.,•••. Ent •.r Stud",,,, ID (Stri"l _ l'ri.nary 11:•.)') IOF01Jl0n For Deletion only Student ID Required Student's data manipulation can be done by using the following page r", r Ex.vrunallonl ro- Exarrunabon2 ..... -.--.,.---"..----......----r--j'-r t!tt1Dl.,-N •• -.-- .:J II Question insertion can be done by using the following page .....• _,_.- ..• ii?' I,i! ! Ai' .,U'__ " (J- '..f, .•. .3. .:J!QI • .:.l~~ .:.... •..rti_";;;;.:;,;;..~;.:.:../,,;;~;.'"~~. -,.,-;.~, ..__.,_._.•. _ .•.. u.!1~!'4- Enl••••••••••••1(S'mtll EnI•• An,,,, •• 2 (stnoe)f ,J{~1 EnI •• "" ••••••. ,,"_ u.... C ••• « •.•.•••••••.• 1'1 •• (lrl••• .1iJ •••• •• 4 (S>J"'&li Froio< ,:f------ -----'---.---------~--------.-----r,r~~...__ -" Question manipulation can be done by using the following page I> ••. ... - ,_. ,- ..• I liM i! .•._ •.•. ~~C1''o:l- .ioI, •••• - a-:;'lJ ~.3'.:JiO:':.::.l':'~ .••••.;. [., •••• /""#.,;,. •••••.•••.••.,t- .•.._ "' .•.•.•_,,1 ," A~.-.2 r "'o ••••• l CM~ •• C"", An, I -"".J .•,,~. :::r~,;-r••• ~ d CM t1•••. V_f,.., ••••o..,l ••f~" •••••. ~~~';':.J~ Il •••• ) 12 Some other pages are also available for performing seeing every student information, Using the following seeing every inserted questions etc. page, particular available examinations necessary tasks as examination can be chosen from by an examinee L~.,..H_ 'ob<~ L~ •••••ID ['FOIJlOIS !r-rQ' ••••• _ Using the following page number of questions per page can be chosen by an examinee L~ •••• II••.•••••.••• L~"",ID r'Fo1l1019 &_, »n •• SC.rI bllUD" 10 pro~""". :.fiiiON"-------------.-.----,."--'--'- ..--,..-.-.-.---- ---.-,.--.--~-.--.--r rrlli;;o .oJ •• -;;;o-- 13 Questions will be generated in a different order for every examinee, so possibility of unfair means has been minimized E', =====i=llljj= roo •.• _ .-., ._ ••• ••••_""'£&UlIl:SOLZO""'=".,,."'==."',..,,=-"'-"'-."'~Z:""~ .~~ •..•. OU.ll~IQ.....;;,--:z'•••.•••'1)_. ;;,,';o . .:.t~.~'t'g ~~.l~.!:.--_~~...:_.!~~" .... ,.""....... L~., 110m< lo",,1P ~.~. __ -_"' ~::::,,:"..J.L"J _ . I ~3~~-ij ft •••• l'f01Jl019 ., QI 2.;<-' q -. co .~ . "".h' Q) (' ••..••• ~rt•••••••• •• Chot"" ..••••• ""C_al.. !" 1:00»" Qol 12'"2'2.1 -" -" ." '.U .••• ,"""'d rrri21.--- Examination score will be shown instantly after pressing the Submit button Lo••• lt...,. •••.••• t •.•••• ID DFOUl019 u_i YOllr Sc;ore is: J.O In 4.0 Perccnl ••ee I,: 75.00°/0 No examinee will be allowed to take the same exam twice without examiner's permission. 14 4.2 Software Testing Tomcat software 3.1M1 and Tomcat to handle the servlets 3.3.1 has been and to generate used with dynamically desired web pages. JDK1.2 and JDK1.3 has been used to for developing software and to cooperate with Tomcat. Windows98, Windows2000 this the Software has been tested in and Linux platform. No significant problems have been found while testing the software. In case of Oracle8i, some methods to manipulate are not available recommended with the to download built in and install JDBC the Resultset driver. It is highly the latest JDBC driver, else program may not function properly. Oracle9i has built in JDBC driver with all necessary methods to manipulate the Resultset. MySQL 3.23 has built in methods to manipulate Resultset and while tested with this software has not shown any considerable errors. Microsoft necessary ODBC methods driver and it for Access is fully database functional with also has the the developed software. Developed software different number having has been tested of questions. with different Scores examinees calculated by the software and scores calculated manually were same. Some examinees name, ID, no of questions tested with and scores are given below Name ID No. of questions score Khairul DF0131099 12 10 Tuhin DF0131079 25 19 Rahim DF0131099 30 25 15 4.3 Software Customization For using other database servers: ,. Some packages needed to be imported programs based on database server. in java servlet Every database servers requites particular package, documentation can be searched for intended database server ,. Particular driver needed to be registered for each database server. Documentation may aid in finding necessary information ,. Connection string needed to be created for the database server. It will be found in the documentation of the database server. ,. Java servlet source files needed to be modified using above three steps, source files needed to be recompiled and byte code files needed to be replaced the in the "classes" folder of the web server. For changing the schema ,. Database administrator has the authority for creating users, privileges and roles. ,. During creation of the database objects given name and password should be used. All tables will be created under given schema ,. User name "scott" and password "tiger" should be chaged with given name and password in every connection string found in LoginCheck.java, GetExam.java, GetMessage.java and GetQuestAns.java. Source files needed to be recompiled and byte code files needed to be replaced the In the "classes" folder of the web server. 16 For changing server name and folder name While requesting the servlets, following should be used < FORMACTION=http://user server name: SOBO/userfolder/servlet/ user servlet METHOD=POST/GET> 4.4 Getting help a) For the standard software, the following web addresses or help files may be searched to get help on relevant topics Oracle http://www .oracle.com, http://education .oracle.com http://technet.oracle.com/docs/, http://www.orafaq.com MySQL: http://www.mysql.com/documentation/ http://www.mysql.com/portal/books/html/index.html. Microsoft Access Database: Built in help with the Access Database JDK: http://java .sun.com/prod ucts/ Tomcat: http://jakarta.apache.org b) To get help for the developed software, file (help.txt) in appendix can be seen. contents of the help 17 Chapter 5 Hardware requirements 5.1 Basic Hardware Minimum configurations of the hardware required for the developed software are described below: Server Side: IRequirement ] Details I pm"~--.--M-in-i-m-a-I-p-ro-c-e-s-s-o-r-: _ I. Recommended Processor: Pentium III or above ~ • I • , Hard disk -P-en-t-iu-m-I-I--------. Typical: 256 MB (512 MB recommended) Minimal installation: 128 MB (256 MB recommended) • Typical installation: 2.9 GB • Minimal installation: 2 GB • Custom installation: depends on components selected for installation. I iWeb • Frames and Java-enabled IOthers • LANCard I browser I 18 Client Side: rRequir;;;entlDetail~ ---.----------------------------.------- 1------- i Processor i i • Minimal processor: Pentium MMX, Pentium Celeron or equivelant. Recommended Processor: Pentium II or above • i ,-----------1---------------------------IRAM • i • ! IH-a--r-d-d-i s-k--j---. --' I Minimal: 64 MB Recommended: 128MB I -S p~~_;-~~-~-e_;;sa-r-y-fo r-i ~~t;jJj-n--g-a-n-y-c-Jj-e--n-t-s--i d-e---I L .. ..__. . _ 5.2 Network Environment Considering different issues and aspects, following networking plan have been proposed: ,. Network should be designed in such a way that all connected workstations smooth way. authentication have the ability to connect to the network in a It should server, have DNS all required server) and software (ex. hardware (ex. Terminal server, Router) that enable remote user to log into the network as well. :.- Developed network should be secured and reliable :.- Round trip time of the network should be minimum :.- Developed network should be designed at a minimum of cost but one that allows for future technologies to be added easily 19 Necessary equipment that may be required to develop a network for local and remote access are listed below: Device Name No. Router 1 Terminal Server 1 Switch 2 Hub 4 CAT 5 UTP Cable 500 metre LAN card 10 Computer 10 20 Server Elh ~ Host_ 2 ~ Hose 5 ~ Hose 8 Host_ 3 ~ HosC6 ~ Host -9 Host_ 4 ~ HosC 7 @J-HosCIO Possible network diagram 21 5.3 Troubleshooting The frequently encountered problems and the methods to solve them are listed below: Problems: ,. Broken or disconnect cables ).- Cables connected to the wrong ports ).- Intermittent cable connection ,. Wrong cables used for the task at hand ).- Transceiver problems or device turned off ,. Improperly configured serial and Ethernet interface ,. Improper clock-rate settings on serial interface ,. Incorrect IP addresses and Subnet Masks ).- Incorrect DNS to IP bindings Solution: ).- Observe some aspect of the universe and invent a theory that is consistent with what you have observed ).- # Use the theory to make predictions ).- Test those predictions by experiments or further observations ).- Modify the theory in the light of your results. ).- Go to step # ).- Identify network/user problem ,. Gather data about network/user ,. Analyze data to come up with problem a possible solution to the correction to the problem ,. Implement solution to network to attempt system ).- If the problem modify data ,. Go to step # isn't resolved, undo previous changes and 22 Chapter 6 Installation 6.1 Oracle Contents in appendix can be seen 6.2 Tomcat Contents in appendix can be seen 6.3 Software Step 1: ,. A folder needed to be created in jakarta-tomcatjwebapps folder (Default is Sohebl) ,. Sub-folders of jakarta-tomcatjwebappsjexamples needed to be copied into the created folder r Html files needed to be placed in the folder created earlier for the application o table.html o question.html o student.html o exam.html r Servlet webappsj class files needed to be placed created folder j WEB-INF jclasses o LoginCheck.class o GetExam.class o GetMessage.c1ass o GetQuestAns.c1ass o AuthenCheck.class in Jakarta tomcatj ?' _J o AuthenCheck1.c1ass o AuthenCheck2.c1ass o CreateTable.class o StudentData.class o QuestionData.class o DeleteRecord.class o DeleteQuestion.c1ass y A mapping needed to be added for the application the jakarta-tomcat/conf/server.xml y by editing . Following needed to be added at the end part of this file <Context path="/Sohebl" docBase="webapps/Sohebl debug = "0" reloadable ="true" > </Context> y Web page can be called address ''http://localhost: Noted that tomcat/we- y Servlets html file to index.html by using the that is placed in jakarta- will be displayed be registered tomcat/webapps/Sohebl/WEBy web-browser SOSO/Sohebl" bapps/Sohebl needed from by INF/web.xml editing jakarta- file Following code for each servlet needed to be added <servlet> <servlet-name> servlet name </servlet-name> <servlet-c1ass> class names of the servlet java jakarta-tomcat/webapps/created </servlet-c1ass> </servlet> file those are placed in folder/WEB-INF/ classes 24 ).- Servlets can be called by http://localhost:BOBO/Sohebl/ servlet/servletname Step 2: Tomcat needed to be started Step 3: Database server needed to be started Step 4: ;;. Connection to the web server (Tomcat) ''http://server name:BOBO/Sohebll" can be made using web browser from server/client machine ;;. If the html pages mentioned above can be seen, installation is successful Chapter 7 Conclusion and Further Work 7.1 Conclusion Design of a program programmer. depends upon the style chosen by. the None can say that his one is the last as better and better solutions are coming everyday. software, some may due to ignorance and some may due to lack of experiences. software. There We may have many limitations are many chances for others in our to enhance We wish best for our followers to give something this better. 7.2 Further work This software has been designed to take multiple required for a particular • for taking improvement multiple examinations course. It is possible to develop the software examinations for multiple courses. Further of the developed software is possible. Some suggestions have been pointed out for the further work: ;... Examination created by ID+Examn, tables Exam 1, Exam2, , Examn using name ID+Exam 1, ID+Exam2, can be , where ID implies Course Identification (Teacher Table's ID Column) I' Multiple Student "ID+Student" table can be created for holding student's by using name, Student's name ID and scores for each course. ;... While taking exams student can be given options to choose a particular method particular course from available used in the software examination courses. Then can be applied from available the same to evaluate a designed for a course. 26 Examination score then can be inserted in the "ID+Student" table, created for a particular course. r In student table Examl, Exam2, , Examn columns can be used to store nested table or varray. This nested tablejvarray can be used to store answers given by the student for later verification r Question bank can be made, from where a given number of questions will populate the exam tables. Database triggers can be used for this purpose ,. While inserting information of a new student in the register office, student table can be updated by using triggers r An extra column in the student value for activation ,. r or deactivation By using multithreading time automatically when time expires present become difficult and technique, examination In the table can be used to hold system to with to maintain of the examinations it is possible to monitor activate new academic submit button session, it will the table with inserted may be possible to add year as "2002" names the data. It to add with all table 27 References [I] JA VA HOW TO PROGRAM BY DEITEL & DEITEL [2] JA VA ONLINE TUTORIAL: TRAIL BY MA YDENE FISHER [3] CORE SERVELETS AND JAVASERVER PAGES BY MARTY HALL [4] ORACLE 8i/9i DOCUMENTATION BY ORACLE CORPORATION [5] ORACLE8i MINDS AND ADMINISTRATION DBA: ARCHITECTURE BY HUNGRY [6] JAKARTA TOMCAT DOCUMENTATION [7] MySQL DOCUMENTATION BY FREE SOFTWARE FOUNDATION 28 Appendix (From Oracle Documentation) Using Oracle Universal Installer Oracle Universal Installer automatically Environment installs the Java Runtime (JRE). The JRE is a subset of the Java (JDK). To run Java applications, applications, JRE is required. Developer To develop Kit Java JDK is required. Non-Interactive Typically, Insta IIation Installer can be run in interactive mode. However, installer in non-interactive or silent mode is available for advanced Oracle Universal users (such as database administrators), by using a response file. This is a text file containing vai-iables and values used by Oracle Universal Installer during the installation process. Using the silent installation enables to bypass the graphical user interface (GUI) and install Oracle products in silent mode. To use a response file, response file should be modified and it is located in the \Response folder located at the root of the Oracle8ij9i Enterprise Edition CD-ROM. Accompanying readme.txt file can be seen for more information. Running the Installation The following Oracle8ij9i steps describe a Typical, interactive Enterprise Edition Minimal or Custom installation for Windows installation NT. Users, choosing may encounter a slightly different of a set of windows. To install a Typical installation for Windows NT: of Oracle8ij9i Enterprise Edition 29 .,. Operating running, system be started. If Windows NT 4.0 is logging to Windows NT server as a member Administrators r should of the group is required All Oracle services should be stopped (if any are running). For Windows NT 4.0, services can be stopped as follows: From the Control Panel, services icon can be selected. If any Oracle services (names begin with Oracle) exist and have the status Started, it should be stopped .,. OracleSi Enterprise CD-ROM drive. the Autorun Windows Edition CD-ROM should The Autorun page does NT Explorer be inserted page automatically not should appear, Start be chosen. into appears. > If Programs> The Windows NT Explorer will start r Navigation to the root directory of the CD-ROM is needed. SETUP.EXE should be double-clicked. Oracle Universal Installer will The welcome screen for appear and installation will begin ;,.. Selection must be made when prompted by the OracieSi Enterprise Edition -Autorun dialog box: Add/Remove Products Explore CD Browse .,. Selecting Add/Remove Products will begin the installation process. The Welcome window will appear ,. Clicking Next is required. The File Locations window will appear. Source ... field must not be changed ,. Oracle Home name and directory OracleSi/9i Enterprise Edition location is required to install components. The default 30 location is <drive with the most available space> :\ORACLE\ORASI or \ORACLE\ORA9I :,...Clicking Next will proceed. The Available Products window will appear ,. Oracle product OracleSij9i should be selected to install is Enterprise Edition) :,...Clicking Next will proceed. The Installation appear. (default Appropriate installation type Types window will is required (Typical, Minimal, or Custom) ,. Clicking Next will Documentation proceed. window The Location for Oracle will appear for a Typical or Custom installation. Hard Drive selection to install the documentation will documentation install documentation :,...Clicking prompt on the hard drive. Otherwise, will remain on the CD-ROM Next will proceed. At this point of the installation, to upgrade database with the Oracle Data Migration Assistant may appear (if Oracle Universal Installer detects an earlier version of an Oracle database on hard drive). Selecting the Migrate an Existing Database check box will make Oracle Data Migration Assistant start immediately migrate existing Identification database. Click after installation Next. The to Database window appears ,. Global Database Name and SID in the fields provided are required :,...Clicking Next will proceed. The Summary window will appear listing the Requirements, Global Settings, Product Languages, and New Installations ,. Install should be clicked. After the components the Space Configuration Tools window will appear are installed, and NetS 31 Configuration Assistant automatically start and other appropriate in succession. The assistants Configuration will Tools window will display the results of running these assistants :.- Clicking Next will proceed. The End of Installation window will appear. :.- Clicking Exit is needed to exit from Oracle Universal Installer or clicking Next is needed to install another product. (From Jakarta Tomcat Documentation) Installing Tomcat This available section deals with installing the Tomcat binary archive from the Jakarta Project. It is also possible to install Tomcat by building it from source, but that isn't covered here. Downloading of the is appropriate jakarta-tomcat-<version> binary archive file necessary. For Linux, RPMs are also available. Archive should be expanded into some directory or C:\). This should create a new subdirectory <version>". use the Renaming this directory new name should named "jakarta-tomcat- is also possible. be followed. (say /usr/local For Linux, Instructions to RPMs may be installed with the command "rpm -Uvh". Command man rpm will give more information. Environment There Tomcat. these Setup are a number of different There are differences methods. This section methods in the environmental addresses the to start setup needed for environmental needed for using the shell scripts and batch files provided starting and stopping Tomcat. and stop to simplify This section assumes manual and stopping of Tomcat from a shell or MS-DOS window. setup starting In a shell <vers;on>" or directory Setting the DOS window, to the "jakarta-tomcat- is required. environment point to the root directory the Java interpreter exact directory change variable JAVA_HOME is required of your JDK hierarchy. to PATH environment to Optional addition variable is possible. of The may vary from system to system. Checking of local file system should be done to be sure where Java is installed. Win32: JAVA_HOME=c:/jdk1.3.1 PATH=%JAVA_HOME% \bin; %PATH% Unix (bash/sh): JAVA_HOME=/usr/localjjava/jdkl.3.1; export JAVA_HOME PATH=$JAVA_HOME/bin: $PATH; export PATH Unix (tcsh): JAVA_HOME=/usr/localjjava/jdkl.3.1 PATH $JAVA_HOME/bin:$PATH TOMCAT_HOME environment variable is optional. shell/batch scripts are executed from from "bin" then its subdirectory, "jakarta-tomcat-<vers;on>" they will successfully TOMCAT_HOME if not already set. If these shell/batch to be executed mandatory. from other If the supplied directories, setting or set scripts needed TOMCAT_HOME is 33 On Win32 systems: TOMCAT_HOME=c: \jakarta-tomcat- <version> On UNIX (using bash/sh): TOMCAT_HOME=/usr/local/jakarta-tomcat- <version>; TOMCAT_HOME On UNIX (using tcsh): > TOMCAT_HOME /usr/local/jakarta-tomcat-<version Starting Tomcat After environment opening a shell or MS-DOS window and as described in the prior section, starting setting the and stopping of Tomcat can be done. Tomcat can be started: On Win32: bin\startup On UNIX: bin/startup.sh This will start Tomcat in the background on Unix based systems, or in a new MS-DOS window on Windows based systems. A short period of time is needed before Tomcat is ready to serve requests. The very first use will need a little extra time since some WAR files will be expanded by default. Whether Tomcat has completed can be verified by its startup, when text like the following appears in the log output. 2001-09-01 14:23:30 - Http10Interceptor: 2001-09-01 14:23:30 - Ajp12Interceptor: Starting on 8007 2001-09-01 14:23:30 - Ajp13Interceptor: Starting on 8009 In Tomcat's assigned to a file. default configuration, Instead, Tomcat's Starting on 8080 Tomcat's log output output log is not goes stderr. On 34 Windows systems, switching to the MS-DOS window can be done to see if this test has appeared. The default Tomcat configuration port 8080. Starting browser will service HTTP requests on with http://localhost:8080/ will present Tomcat's Welcome page. In addition to serving HTTP, the default configuration will service Ajp12 protocol requests on port 8007 and Ajp13 protocol requests on 8009. which These Tomcat protocols are used by the to be used as a Servletj]SP "connectors" container allow for an external web server, such as Apache. Also, the Ajp12 protocol is used by the Tomcat shutdown process. Options and system property settings can be passed to the Java VM by specifying them TOMCAT_OPTS (for enhancement instance: if in an environment '-server' running is useful Sun's variable called as a performance HotSpot VM). Note: On Win9x, it's not possible to include system property settings in TOMCAT_OPTS because the SET command won't accept a line with more than one equals sign. The servers, "auto-generated" configuration such as Apache, are not written Tomcat. To write the configuration command. Tomcat will initialize files for during a normal files, append jkconf sufficiently external web startup of to the startup to write the files and then exit. This may be done while the Tomcat is running as a web server. Stopping Tomcat To perform a normal shutdown of Tomcat, a special "shutdown" request must be send from a separate process, or possibly a different computer. In the default configuration, that "shutdown" request must be made using the Ajp12 protocol. If the shell or MS-DOS window used 35 to start Tomcat is not still open, opening a new one is essential and environment should be set as same as for starting Tomcat. Tomcat can be stopped: On UNIX: bin/shutdown.sh On Win32: bin\shutdown The shutdown process incorporates password. In the default configuration, This means computer being that Tomcat that started This shutdown Tomcat: means protocol. that host, port, and a the host defaults to localhost. be shutdown it. The port automatically used by the Ajp12 specified". can only a defaults The password a password will from not the to the port defaults be same to "not required to 36 Developed Software Some frequently occurred problems and their solutions are given below Ql. Tomcat cannot be started, what can be done? Ans. Oracle's TNSListener should be stopped, Tomcat should be started (TNSListener should be started again). Q2. Required html pages can not be found, what can be done? Ans. Stepl> Given URL should be checked, if URL is ok step 2 should be followed else it must be fixed. Step2> With http://Iocalhost:8080/ uri, if Tomcat's starting page comes, Step 4 should be followed else Step 3. Step3> If Tomcat is not running, Starting Tomcat Section in the appendix section can be seen. Step4> Web folder, context mapping and servlet registration should be checked for errors. Q3. Invalid argument call error has shown, what should be done? Ans. This problem can be solved by filling imperative Q4.How network adapter connection Ans. Oracle TnsListener Q5. How connection text boxes. problem can be solved? should be started. refusal problem can be solved? Ans. Database should be mounted and opened .. 37 Q6. Invalid username and password error, how to eliminate? Ans. Spelling administrator should be checked, if it doesn't work database should be consulted. Q7. Deletion of any data without giving Student ID or Question Number is possible, why? Ans. No actual row will be deleted from the tables. Q8. Data can not be inserted or modified, why? Ans. All mandatory text boxes needed to be filled. Q9. While there are question in tables it shows no question is available, how to solve? Ans. Due to connection back and then returning Ql0. problem it may happen, moving one pages will solve the problem How number of questions per pages can be changed after starting the examination Ans. Once examination is started this option can not be changed. Ql1. Table's can not be created, why? Ans. Old tables with the same name should be deleted (All old information will be erased) Q12. What will happen, if database objects are created in different schemas. Ans. Username and password used in Module - 4 Source Codes should be changed. Otherwise students will not be able to connect. VOLUME - II Module 1 Codes necessary for creating database tables. table.html <HTML> <HEAD> <TITLE >LOGIN </TITLE> </HEAD > < BODY>< FORMACTION= http://localhost :SOSO/Sohebl/servlet/ AuthenCheck METHOD=POST> <H3>Please enter login name and identification number.</H3><BR> <PRE> Name: <INPUT TYPE=text NAME=Name> ID: <INPUT TYPE=text NAME=ID> </PRE> <INPUT TYPE=SUBMIT value=Submit> <INPUT TYPE=reset> </FORM> </BODY> </HTML> Authencheck.java import java.sql. *; import javax.swing.*; import oracle.sql. *; import java.io. *; import javax.servlet. *; import javax.servlet.http. *; import java.util.*; import oracle.jdbc.driver. *; import java.math.*; //AuthenCheck will check for valid user in the database public class AuthenCheck extends HttpServlet { Cannection conn; Statement stmt; ResultSet rset; public void init(ServletConfig config) throws ServletException { 2 super.init( config); ) public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException { int i=O,exams; PrintWriter output; / /Tname for holding Teacher Name and Tid for holding Teacher ID String Tname='''',Tid=''''; Tname= req.getPara meter("'Name"); if(Tname==null) Tname=Tname+"@"; Tid = req .getParameter("ID"); if(Tid==null) Tid=Tid+"@"; String stl,st2; boolean identification=false; try { DriverManager. registerDriver (new oracle.jdbc.driver.OracleDriverO); conn = DriverManager.getConnection ("jdbc: oracle :thin:@netvista103: 1521: soh9i 1",Tname, Tid); stmt = conn.createStatement 0; rset = stmt.executeQuery ("select D. * from dual D"); identification =true; } catch(Exception sqlex) { output= res.getWriter(); res.setContentType( "text/html"); output.println(" <H2 >Check following errors</H2>"); output. println (sqlex); output.closeO; } if (identification) { Cookie c1=new Cookie("Tname",Tname); c1.setMaxAge( -10); Cookie c2=new Cookie("Tid",Tid); c2.setMaxAge( -10); res.addCookie(c1) ; res.addCookie(c2) ; output= res.getWriterO; res.setContentType( "text/html"); String Buffer buf=new StringBuffer(); buf.append(" < HTML>< HEAD><TITLE>"); buf.append("Table Creation Page"); buf.append (" </TITLE> </HEAD> < BODY>"); buf.append(" < FORMACTION= http://netvista 103: 8080/Sohebl/servlet/CreateTable METHOD=POST>"); buf.append("<BR>"+"<H3>Please Enter Course ID (String)</H3>"); buf.append("<INPUT TYPE=text NAME=courseid>"+"<BR>"); buf.append("<BR>"+"<H3>Please Enter Number of Examinations(Integer)</H3>"); buf.append(" <INPUT TYPE=text NAME=examno>"+" <BR><BR>"); buf.append(" <INPUT TYPE=Submit Vaiue=Submit>"+"<BR>"); buf.append(" </FORM> </BODY> </HTM L>"); output. println( buf.toString()); output.c1ose() ; } } public void destroy() { try { conn .close(); }catch(Exception e) {System.err.println("Problem closing the database");} } } CreateTable.java import java.sql. *; import javax.swing. *; import oracle.sql. *; import java.io. *; import javax.servlet. *; import javax.servlet.http. *; import java.util. *; import oracle.jdbc.driver. *; import java.math. *; //CreateTable will creates necessary tables in the database under teacher schema public class CreateTable extends HttpServlet { Connection conn; Statement stmt; 4 ResultSet rset; public void init(ServletConfig config) throws ServletException { super.init( config); } public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException { PrintWriter output; Cookie cookies[]=null; cookies= req .getCookies(); / / Retrieving Teacher Name and ID from cookies String Tna me= "" ,Tid = "" ,course= null,examno_string =null; int examno=O,exam=O; course= req .getParameter("courseid"); examno_string = req .getParameter("examno"); if (cookies' =null) { for (int i=O;i<cookies.length;i++) { Cookie cookie = null; cookie=cookies[i] ; if( (cookie.getName()) .equals("Tname")) Tname=cookie.getValue(); if( (cookie.getName()) .equals("Tid")) Tid =cookie.getValue(); } } try { examno= Integer. parseInt( examno_string); }catch(NumberFormatException e) { output= res.getWriter(); outpuLprintin("<H2 >Check following errors soheb</H2>"); output. println( e); res.setContentType("text/html") ; String Buffer buf= new StringBuffer(); buf.a ppend(" < HTML> < HEAD> <TITLE>"); buf.append("Table Creation Page"); buf.a ppend(" </TITLE> </HEAD> < BODY>"); buf.append(" < FORMACTION= http://netvista 103 :8080/Soheb l/servlet/ AuthenCheck METHOD=POST>"); buf.append("<INPUT TYPE=HIDDEN NAME=ID VALUE="+ Tid+" >"); buf.append("<INPUT TYPE=HIDDEN NAME=Name VALUE="+ Tname+">"); buf.append(" <BR><INPUT TYPE=Submit Value= Back>"+"<BR>"); buf.append("' </FORM > </BODY> output. println( buf. toString(»; output.close() } try </HTML>"); ; { DriverManager .reg isterDriver(new oracle.jdbc.d river.OracleDriver(»; conn = DriverManager.getConnection("jdbc: oracle :thin:@netvistal03: 1521 :soh9i 1", Tname, Tid); stmt = conn.createStatement (); I I Creating Teacher Table rset = stmt.executeQuery ("CREATE TABLE Teacher(ID VARCHAR2(15) CONSTRAINT Teacher_Prim PRIMARY KEY,Exams NUMBER(4) )"); rseLclose() ;stmLclose(); stmt = conn.createStatement (); II Inserting Course Name and No. of Examinations rset = stmLexecuteQuery("INSERT in the Teacher Table INTO Teacher VALUES(''' +course+ '" ," +examno+")"); rset.close() ;stmt.close(); stmt = conn .createStatement(); ("'Select T. * from Teacher T"); rset = stmt.executeQuery while (rset.next()) { exam=rset.getlnt(2) ; } rset.close() ;stmt.close(); stmt = conn.createStatement(); IICreating Examl, Exam2, ,Examn Tables for (int i=O;i<exam;i++) { String name="Exam"; name=name+(i+ 1); rset = stmt.executeQuery ("CREATE TABLE "+name+" (No Number(4) UNIQUE CONSTRAINT NotNull_Number"+i+" CONSTRAINT Unique_Number"+i+" NOT Null,Quest VARCHAR2(200),Ansl VARCHAR2( 50) ,Ans2 VARCHAR2( 50) ,Ans3 VARCHAR2( 50) ,Ans4 VARCHAR2(50),Correct VARCHAR2(5»)"); 6 } rset.c1ose() ;stmLclose(); stmt = conn.createStatement(); rset = stmLexecuteQuery ("Select T. * from Teacher T"); while (rset.next()) { exam=rset.getlnt(2) ; } rset.c1ose() ;stmt.close(); stmt = conn.createStatement(); ((Creating Student Table rset = stmt.executeQuery ("CREATETABLE Student(ID VARCHAR2(15) CONSTRAINT Student]rim PRIMARY KEY,Name VARCHAR2(30) CONSTRAINTStudenCName NOT NULL)"); rset.close() ;stmLclose(); stmt = conn.createStatement(); for (int i=O;i<exam;i++) { String name="Exam"; name=name+ (i+ 1); rset = stmt.executeQuery ("ALTER TABLE Student ADD ("+name+" NUMBER(4))"); } conn.c1ose() ; output= res.getWriter(); res.setContentType("text(html") ; output. println(" <H2> Tables Created«H2 >"); outpuLclose() ; }catch(Exception sqlex) { output= res.getWriter(); output.println(" <H2 >Check following errors«H2 >"); output. println(sqlex); res.setContentType("text(html") ; String Buffer buf=new StringBuffer(); buf.append (" <HTML> < HEAD> <TITLE>"); buf.append("Table Creation Page"); buf.append(" «TITLE> «HEAD> < BODY>"); buf.append(" < FORMACTION= http:((netvista103:8080(Sohebl(servlet(AuthenCheck METHOD=POST>"); buf.append("<INPUT TYPE=HIDDEN NAME=ID VALUE="+ Tid+">"); buf.append("<INPUT TYPE=HIDDEN NAME=Name VALUE="+Tname+">"); 7 buf.append(" <BR><INPUT TYPE=Submit Value=Back>"+"<BR>"); buf.a ppend(" </FORM > </BODY> </HTML>"); output. println( buf.toString(»; output.close() ; } } public void destroy() { try { conn .close(); }catch(Exception e) {System.err.println("Problem } } closing the database");} 8 Module 2 Codes necessary for inserting and manipulating students information in Student table student.html <HTMl> <HEAD> <TITLE >lOGIN </TiTlE > </H EAD> < BODY><FORM ACTION= http://localhost: 8080/Sohebl/servlet/ AuthenCheckl METHOD=POST> <H3>Please enter login name and identification number.</H3><BR> <PRE> Name: <INPUT TYPE=text NAME=Name> ID: <INPUT TYPE=text NAME=ID> </PRE> <INPUT TYPE=SUBMIT value=Submit> <INPUT TYPE=reset> </FORM> </BODY> </HTMl> AuthenChecklJava import java.sql. *; import javax.swing. *; import oracle.sql. *; import java.io. *; import javax.servlet. *; import javax.servlet.http. *; import java.util.*; import oracle.jdbc.driver. *; / / AuthenCheckl will check for valid user in the database public class AuthenCheckl extends HttpServlet { Connection conn; Statement stmt; ResultSet rset; public void init(ServletConfig config) throws ServletException 9 { super. init( config); conn=null; stmt=null; } public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException { int i=O,exams; PrintWriter output; / /Tname for holding Teacher Name and Tid for holding Teacher ID String Tname="",Tid=""; Tname= req .getParameter(" Name"); if(Tname==null) Tname=Tname+"@"; Tid = req .getParameter("ID"); if(Tid==null) Tid=Tid+"@"; String stl,st2; booiean identification=false; try { DriverManager. registerDriver (new oracle.jdbc.driver.OracleDriver(); conn = DriverManager.getConnection("jdbc:oracle :thin:@netvista103: 1521: soh9i 1",Tname, Tid); stmt = conn.createStatement 0; rset = stmt.executeQuery ("select D. * from dual D"); identification =true; }catch(Exception sqlex) { output= res.getWriter(); res.setContentType("text/html") output.println("<H2>Check ; following errors</H2>"); output. println(sqlex); output.close() ; } if (identification) { Cookie c1=new Cookie("Tname",Tname); c1.setMaxAge( -10); Cookie c2=new Cookie("Tid",Tid); c2.setMaxAge( -10); res.addCookie(c1) ; 10 res.addCookie(c2) ; output= res.getWriter(); res.setcontentType("text/html") ; String Buffer buf=new StringBuffer(); buf.append(" < HTML>< HEAD><TITLE>"); buf.append("Table Creation page"); buf.append(" </TlTLE> </HEAD> < BODY>"); buf.append(" < FORMACTION= http://netvista 103: BOBo/soheb1/servlet/StudentData METHOD=POST>"); buf.append(" < BR>" +" < H3> Please Enter Student Name (String) </H3 >"); buf.append("<INPUT TYPE=text NAME=stdname size=30>"+"<BR>"); buf.append("<BR>"+"<H3>Please Enter Student 10 (String - Primary Key)</H3>"); buf.append("<INPUT TYPE=text NAME=stdid size=15>"+"<BR><BR>"); buf.append("<BR>"+"<H2>For Deletion only Student 10 Required</H2><BR>"); buf.append("<INPUT TYPE=Submit name=Student Value=Enter>"); buf.append("<INPUT TYPE=Submit name=Student Value=Delete>"); buf.append("<INPUT TYPE=Submit name=Student value=AIIStudents>"); buf.append("<INPUT TYPE=Submit name=Student value=Exit>"); buf.append(" </FORM> </BODY > </HTML>"); output.println(buf.toString()) ; outPut.c1ose() ; } } public void destroy() { try { conn.c1ose(); }catch(Exception e) {system.err.println("problem closing the database");} } } StudentData.java import java.sql.*; import javax.swing.*; import oracle.sql. *; import java.io.*; import javax.servlet.*; import javax.servlet.http. *; import java.util.*; import oracle.jdbc.driver.*; II IIStudent Data to insert, update student information public class StudentData extends HttpServlet { Connection conn; Statement stmt; ResultSet rset; public void init(ServletConfig config) throws ServietException { super.i nit( config); } public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException { PrintWriter output; Cookie cookies[]=null; cookies= req .getCookies(); II stdid= Student ID, stdname= Student Name, surf= holds option String Tname= "" ,Tid = "" ,stdid =null ,stdname= null,surf=""; int examno=O,exam=O; stdid = req.getParameter("stdid"); stdname= req .getParameter("std name"); if (cookiesl =null) { for (int i=O;i<cookies.length;i++) { Cookie cookie = null; cookie=cookies[i] ; if( (cookie.getName()) .equals("Tname")) Tna me=cookie.getValue(); if( (cookie.getName()) .equals("Tid")) Tid =cookie.getValue(); } } try { DriverManager. registerDriver( new oracle .jd bed river. OracieDriver()) ; conn = DriverManager.getConnection("jdbc: oracle: thin:@netvista103: 1521: soh9i 1",Tname, Tid); stmt = conn.createStatement(); rset = stmt.executeQuery("SELECT T* FROMTEACHERT"); rset.next() ; exa mno= rset.getlnt("Exams"); rseLclose() ;stmt.close(); }catch(Exception sqlex){} if( req .getParameter("Student") .equaIs(" Enter")) surf= "Enter"; 12 if( req .getParameter("Student") .equals("Delete"» surf="Delete"; if( req .getParameter("Student") .equals(" AIIStudents"» surf="AIiStudents"; if( req .getParameter("Student") .equals("Exit"» surf="Exit"; if (surf.equals("Exit"» { I ITo exit output= res.getWriter(); res.setContentType("text/html") ; String Buffer buf=new StringBuffer(); buf.append(" < HTML> < HEAD><TITLE>"); buf.append(" </TITLE > </HEAD > < BODY>"); buf.append(" <FORM ACTION=http://netvista 103: 8080/Sohebl/servieti METHOD=POST>"); buf.append("<H3>Please buf.append("Name: AuthenCheckl enter login name and identification number. </H3 > < BR>"); "+"<INPUT TYPE=text NAME=Name><BR>"); buf.append("ID:"+" <INPUT TYPE=text NAME=ID><BR>"); buf.append("<INPUT TYPE=Submit Value=Submit>"); buf.append("<INPUT TYPE=Reset>"); buf.append(" </FORM > </BODY> </HTML>"); output. println(buf.toString (»; output.c1ose() ; } if (surf.equals("Enter")) { I I For insertion new student try { stmt = conn.createStatement(); rset = stmt.executeQuery("INSERT INTO Student(ID,Name) VALUES('''+stdid+ ,n, '" +std name+ ,n)"); rset.close() ;stmt.close(); stmt = conn.createStatement(); rset = stmt.executeQuery("COMMIT"); output= res.getWriter(); output. println (" <H2 >Inserted SuccessfullY</H2 >"); res.setContentType( "text/html"); String Buffer buf= new String Buffer(); buf.a ppend(" < HTML>< HEAD> <TITLE> "); buf.append("Insertion Creation Page"); buf.a ppend(" </TITLE> </HEAD> < BODY>"); 13 buf.append("<FORM ACTION= http://netvista 103: SOSO/soheb1/ servlet/ AuthenCheck 1 METHOD=POsT>"); buf.append("<INPUT 1YPE=HIDDEN NAME=ID VALUE="+ Tid+">"); buf.append("<INPUT 1YPE=HIDDEN NAME=Name VALUE="+ Tname+">"); buf.append("<BR> <INPUT 1YPE=submit Value=More>"+"<BR>"); buf.append(" </FORM > </BODY> </HTML>"); output. println( buf.tostring()); outpuLclose() ; rseLclose() ;stmt.close(); }catch(Exception sqlex) { output= res.getWriter(); output.println(" <H2>Check following errors soheb</H2 >"); output. println (sqlex); res.setContentType("text/html") ; stringBuffer buf= new stringBuffer(); buf.append(" < HTML>< HEAD> <TITLE>"); buf.append("Table Creation Page"); buf.append(" </TITLE> </HEAD > < BODY>"); buf.append("<FORM ACTION= http://netvista 103: SOSO/soheb l/servlet/ AuthenCheck 1 METHOD=POsT>"); buf.append("<INPUT 1YPE=HIDDEN NAME=ID VALUE="+ Tid+">"); buf.append("<INPUT 1YPE=HIDDEN NAME=Name VALUE="+ Tname+">"); buf.append(" <BR><INPUT 1YPE=submit Value= Back>"+"<BR>"); buf.append(" </FORM > </BODY > </HTML>"); output. println (buf. tostring()); outpuLclose() ; } } if (surf.equals("Delete")) { / / For deleting student's information try { output= res.getWriter(); res.setContentType("text/html") ; String Buffer buf=new stringBuffer(); buf.a ppend(" < HTML>< HEAD><TITLE >"); buf.append("Deletion Creation Page"); buf.append(" </TITLE > </HEAD > < BODY>"); 14 buf.a ppend(" < FORMACTION= http://netvista METHOD=POsT>"); 103: 8080/soheb 1/servlet/DeleteRecord buf.append (" <INPUT TYPE=radio NAME=ExamName VALUE=AIl>" + "All" +" < BR>"); for(int j=O;j<examno;j++) { buf.append("<INPUT TYPE=radio NAME=ExamName VALUE=Exam"+(j+ 1)+" CHECKED>"+"Examination"+(j+ 1)+" <BR>"); } buf.append("<INPUT TYPE=HIDDEN NAME=ID VALUE="+Tid+">"); buf.append("<INPUT TYPE=HIDDEN NAME=Name VALUE="+ Tname+">"); buf.append("<INPUT TYPE=HIDDEN NAME=stdid VALUE="+stdid+">"); buf.append("<BR><INPUT TYPE=submit Value=Done>"+"<BR>"); buf.append(" </FORM > </BODY> </HTM L>"); output. println( buf.tostring 0); output.closeO; }catch(Exception { sqlex) output= res.getWriterO; output.println("<H2>Check output. println(sqlex); following errors</H2>"); res.setContentType("text/html") ; String Buffer buf=new stringBufferO; buf.a ppend(" < HTML>< HEAD> <TITLE>"); buf.append("Table Creation Page"); buf.append(" </TITLE> </HEAD> < BODY>"); buf.append(" <FORM ACTION=http://netvista METHOD=POsT>"); 103: 8080/sohebl/servletl AuthenCheck 1 buf.append("<INPUT TYPE=HIDDEN NAME=ID VALUE="+Tid+">"); buf.append("<INPUT TYPE=HIDDEN NAME=Name VALUE="+ Tname+">"); buf.append("<BR><INPUT TYPE=submit Value=Back>"+"<BR>"); buf.a ppend(" </FORM > </BODY> </HTM L>"); output. println (buf.tostring()); output.close() ; } } if (surf.equals("Alistudents")) { liTo see all student try { stmt = conn.createstatement(); 15 rset = stmt.executeQuery("Select output= res.getWriter(); res.setContentType("text/html") S.* FROMSTUDENTS"); ; String Buffer buf=new String Buffer() ; buf.append(" < HTML> < HEAD> <TITLE>"); buf.append("student Information Page"); buf.append(" «TITLE> «HEAD> < BODY>"); buf.append("<FORM ACTION=http:((netvistal03:8080(sohebl(servlet(AuthenCheckl METHOD=POsT>"); while (rset.next()) { for(int i=1;i<=(examno+2);i++) { String temp=""; temp= rset.getString( i); if(temp==null) temp="N/A"; buf.append(temp+" -- "); } buf.append(" <BR>"); } buf.append("<INPUT TYPE=HIDDEN NAME=ID VALUE="+ Tid+">"); buf.append("<INPUT TYPE=HIDDEN NAME=Name VALUE="+ Tname+">"); buf.append(" < BR> < BR> <INPUT TYPE=submit Value=Back>"+"<BR>"); buf.append(" </FORM > </BODY> </HTM L>"); output. println( buf. toString()); output.close() ; rset.close() ;stmt.close(); }catch(Exception sqlex) { output= res.getWriter(); output.println("<H2>Check following errors</H2>"); output. println(sqlex); res.setContentType("text/html") ; StringBuffer buf=new stringBuffer(); buf.append(" < HTML>< HEAD><TITLE> "); buf.append("Table Creation Page"); buf.a ppend(" «TITLE> </HEAD > < BODY>"); buf.append(" <FORM ACTION= http://netvista 103: 8080/Sohebl(servlet( AuthenCheck 1 METHOD=POST>"); buf.append("<INPUT TYPE=HIDDEN NAME=ID VALUE="+ Tid+">"); 16 buf.append("<INPUT TYPE=HIDDEN NAME=Name VALUE="+ Tname+">"); buf.append(" <BR> <INPUT TYPE=Submit Value= Back>"+"< BR>"); buf.append (" </FORM > </BODY > </HTML>"); output. println( buf. toString()); output.c1ose() ; } } } public void destroy() { try { conn.close(); }catch(Exception e) {System.err.println("Problem closing the database");} }} DeleteRecord.java import java.sql.*; import javax.swing. *; import oracle.sql. *; import java.io.*; import javax.servlet. *; import javax.servlet.http. *; import java.uti!. *; import oracle.jdbc.driver. *; / /DeleteRecord will remove any particular user's record public class DeleteRecord extends HttpServlet { Connection conn; Statement stmt; ResultSet rset; public void init(ServletConfig config) throws ServletException { super. init( config); conn=null; stmt=null; } public void doPost(HttpServletRequest IOException { PrintWriter output; req,HttpServletResponse res) throws 17 Cookie cookies[]=null; cookies= req .getCookies(); II Retrieving Teacher Name, ID, Student ID, Teacher's option etc. String Tname= "", Tid = "" ,stdid = null,option = ''''; int examno=O,exam=O; stdid = req .getPa rameter("stdid"); option = req .getPa rameter("Exa mName"); if (cookies! =null) { for (int i=O;i<cookies./ength;i++) { Cookie cookie = null; cookie=cookies[i] ; if( (cookie.getName() if( (cookie.getName(» } .equals("Tname"» Tna me=cookie.getValue(); .equals("Tid"» Tid =cookie.getValue(); } if( option .equals("AII"» { I I For deletion of the full record of a particular student try { DriverManager. reg isterDriver( new oracle .jd bc.driver. OracleDriver(» ; conn = DriverManager.getConnection("jdbc: Tid); oracle: thin:@netvista103: 1521 :soh9i 1", Tname, stmt = conn.createStatement(); rset = stmt.executeQuery("DELETE rset.close() ;stmt.c1ose(); FROM Student WHERE ID='''+stdid+'''''); stmt = conn,createStatement(); rset = stmt.executeQuery("COMMIT"); output= res.getWriter(); output.println("<H2>Deleted Successfully (Also shows Deleted when no match found)</H2>"); res.setContentType("text/html") ; String Buffer buf= new String Buffer(); buf,append (" < HTML>< HEAD> <TITLE>"); buf.append("Insertion Creation Page"); buf.a ppend(" </TITLE> </HEAD > < BODY>"); buf,append("<FORM ACTION=http://netvista METHOD=POST>"); 103: 8080/Soheb1/servieti AuthenCheck1 18 buf.append("<INPUT TYPE=HIDDEN NAME=ID VALUE="+Tid+">"); buf.append("<INPUT TYPE=HIDDEN NAME=Name VALUE="+ Tname+">"); buf.append(" <BR> <INPUT TYPE=Submit Value= More>"+" <BR>"); buf.append(" </FORM > </BODY> </HTML>"); output. println( buf. toString(»; output.close() ; rset.closeO ;stmt.c1oseO; }catch(Exception sqlex) { output= res.getWriter(); output.println("<H2>Check output. println(sqlex); following errors</H2 >"); res.setContentType("text/html") ; StringBuffer buf=new StringBufferO; buf.append (" < HTML>< HEAD> <TITLE >"); buf.append("Table Creation Page"); buf.append(" </TITLE> </HEAD> < BODY>"); buf.append(" <FORM ACTION= http://netvista METHOD=POST>"); 103: 8080/Soheb1/serviet/ AuthenCheck 1 buf.append("<INPUT TYPE=HIDDEN NAME=ID VALUE="+ Tid+">"); buf.append("<INPUT TYPE=HIDDEN NAME=Name VALUE="+ Tname+">"); buf.append(" <BR><INPUT TYPE=Submit Value=Back>"+"<BR>"); buf.append("</FORM ></BODY> </HTML>"); output. println( buf.toString()); output.close() ; } } else { try { / / For deletion based on user option DriverMa nager. registerDriver( new oracle.jd be.driver. OracleDriver(») ; conn = DriverManager.getConnection("jdbc:oracle:thin: Tid); @netvista103: 1521 :soh9i 1",Tname, stmt = conn.createStatementO; rset = stmt.executeQuery("UPDATE Student SET "+option+"=NULL ID= 'II + stdid+ '1111); rset.close() ;stmt.cioseO; stmt = conn.createStatementO; WHERE 19 rset = stmt.executeQuery("COMMIT"); output= res.getWriter(); output.println("<H2>Deleted Successfully (Also shows Deleted when no match found)</H2>"); res.setContentType("text/html") ; StringBuffer buf=new StringBuffer(); buf.append(" < HTML> < HEAD> <TITLE>"); buf.append("Insertion Creation Page"); buf.append (" </TITLE > </HEAD > < BODY>"); buf.append(" <FORM ACTION =http://netvista 103: 8080/Sohebl/servlet/ AuthenCheck 1 METHOD=POST>"); buf.append("<INPUT TYPE=HIDDEN NAME=ID VALUE="+ Tid+">"); buf.append("<INPUT TYPE=HIDDEN NAME=Name VALUE="+ Tname+">"); buf.append("<BR><INPUT TYPE=Submit Value=More>"+"<BR>"); buf.append(" </FORM > </BODY> </HTML> "); output. println(buf. toString(»; output.close() ; rset.close() ;stmt.close(); }catch(Exception sQlex) { output= res.getWriter(); output.println("<H2>Check following errors</H2>"); output. println(sqlex); res.setContentType("text/html") ; String Buffer buf=new String Buffer() ; buf.append (" < HTML> < HEAD> <TITLE>"); buf.append("Table Creation Page"); buf.append (" </TITLE > </HEAD > < BODY>"); buf.append(" <FORM ACTION= http://netvista METHOD=POST>"); buf.append("<INPUT buf.append("<INPUT 103 :8080/Soheb 1/servlet/ AuthenCheck 1 TYPE=HIDDEN NAME=ID VALUE="+ Tid+">"); TYPE=HIDDEN NAME=Name VALUE="+ Tname+">"); buf.append("<BR><INPUT TYPE=Submit Value=Back>"+"<BR>"); buf.append(" </FORM > </BODY> </HTML>"); output. println(buf.toString output.close() ; } } } } (»; 20 Module 3 Codes for insertion and manipulation question in Exams tables questiondata.html <HTMl> <HEAD> <TITLE >lOGIN </TiTlE> </HEAD> < BODY> < FORMACTION= http://localhost: SOSO/Sohebl/servlet/ AuthenCheck2 METHOD=POST> <H3>Please enter login name and identification number.</H3><BR> <PRE> Name: <INPUT TYPE=text NAME=Name> ID: <INPUT TYPE=text NAME=ID> </PRE> <INPUT TYPE=SUBMIT value=Submit> < I NPUT TYPE= reset> </FORM> </BODY> </HTMl> AuthenCheck2Java import java.sql. *; import javax.swing. *; import oracle.sql. *; import java.io. *; import javax.servlet. *; import javax.servlet.http. *; import java.util. *; import oracle.jdbc.driver. *; //AuthenCheck2 will check for valid user in the database public class AuthenCheck2 extends HttpServlet { Connection conn; Statement stmt; ResultSet rset; public void init(ServletConfig { config) throws ServletException 21 super.init( config); conn=null; stmt=null; } public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException { int i=O,exams=O,examno=O; PrintWriter output; / /Tname for holding Teacher Name and Tid for holding Teacher ID String Tname="It,Tid=""; Tname= req .getParameter("Name"); if(Tname==null) Tname=Tname+"@"; Tid = req .getParameter("ID"); if(Tid==null) Tid=Tid+"@"; String stl,st2; boolean identification=false; try { DriverManager. reg isterDriver (new oracl e.jd bed river. OracleDriver()); conn = DriverManager.getConnection("jdbc: Tid); stmt = conn.createStatement rset = stmt.executeQuery oracle :thin:@netvista103: 1521: soh9i 1",Tname, (); ("select D. * from dual D"); identification =true; rset. close() ;stmt.c1ose(); }catch(Exception sqlex) { output= res.getWriter(); res.setContentType("text/html") output.println("<H2>Check output. println(sqlex); output.c1ose() ; } ; following errors</H2>"); if (identification) { Cookie c1=new Cookie("Tname",Tname); c1.setMaxAge( -10); Cookie c2=new Cookie("Tid",Tid); c2.setMaxAge( -10); res.addCookie( c1); 22 res.addCookie(c2) ; try { stmt = conn.createStatement(); rset = stmt.executeQuery("SElECT T.* FROMTEACHERT"); rset.next() ; examno= rset.getlnt(" Exams"); rset.c1ose();stmt.close(); }catch(Exception sqlex){} output= res.getWriter(); res.setContentType("text/html") ; String Buffer buf=new StringBuffer(); buf.append (" < HTMl> < HEAD><TITLE>"); buf.append("Question Manipulation Page"); buf.a ppend(" </TITlE> </HEAD> < BODY>"); buf.append(" < FORMACTION= http://netvista 103: 8080/Soheb l/servlet/Question METHOD=POST>"); buf.append("<BR>"+"<H3>Please Choose an Exam</H3>"); for(int j=O;j <examno;j++) { buf.append("<INPUT TYPE=radio NAME=Examname VAlUE=Exam"+(j+ 1)+" CHECKED>"+"Examination"+ (j+ 1)+"<BR>"); } buf.append("<BR><BR>"+"<H4>**For only**</H4>"); buf.append("Question No.(Integer)"+" Deletion, question No. Required "+"<INPUT TYPE=text NAME=questno>"); buf.append("<BR><BR>"+"Enter Question (String)"); buf.append("<p><textarea rows= 7 name=Quest cols=80></textarea for(i=0;i<4;i++ > </p>"); ) { buf.append("<BR>"+"Enter Answer"+(i+l)+" (String)"+" buf.append("<INPUT TYPE=TEXTNAME=Ans"+(i+l)+" "); SIZE=80>"); } buf.a ppend(" < BR>" +" Enter Correct Answer No.(Integer)"); buf.append("<INPUT TYPE=text NAME=Rightans>"+"<BR> < BR>"); buf.append(" <INPUT TYPE=Submit name=Student Value=Enter>"); buf.append("<INPUT TYPE=Submit name=Student Value=Delete>"); buf.append("<INPUT TYPE=Submit name=Student Value=AIIQuestion>"); buf.append("<INPUT TYPE=Submit name=Student Value=Exit>"); buf.a ppend(" </FORM> </BODY> </HTMl> "); output. println( buf.toString(»; output.close() ; Data } } public void destroy() { try { conn.close(); }catch(Exception e) {System.err.println("Problem } } closing the database");} QuestionData.java import java.sql.*; import javax.swing. *; import oracle.sql. *; import java.io. *; import javax.servlet. *; import javax.servlet.http. *; import java.util. *; import oracie.jdbc.driver. *; IIQuestionData will be used to insert questions in the Examl, ,Examn Tables. public class QuestionData extends HttpServlet { Connection conn; Statement stmt; ResultSet rset; public void init(ServletConfig config) throws ServletException { super. init( config); } public void doPost(HttpServletRequest req,HttpServ/etResponse res) throws IOException { PrintWriter output; Cookie cookies[]=null; cookies= req .getCookies(); II Tname=Teacher Name,Tid=Teacher ID,questno=Question NO., question=Question, ansi =Answerl.. ... Ilsurf=Option (Enter, Delete, All Questions, Exit), exam= Exam Name String Tname="" ,Tid ='''' ,questno= null ,quest= null,ans I =null,ans2 = null, ans3 = null,a ns4= null,surf= null,exam= nuil; 24 int examno=O,qno=O; exa m= req .getParameter("Examname"); questno= req .getParameter("questno"); quest= req .getParameter("Quest"); ansI =req.getParameter("Ansl "); ans2 = req .getparameter("Ans2"); ans3 = req .getParameter("Ans3"); ans4=req .getParameter("Ans4"); String rightans= req .getPara meter("Rightans"); if (cookies! =nul/) { for (int i=O;i<cookies.iength;i++) { Cookie cookie = nul/; cookie=cookies[l] ; if( (cookie.getName()) .equa!s("Tname")) Tname=cookle.getValue(); If( (cookie.getName()) .equals("Tid")) Tid =cookie.getValue(); } } try { DriverMa nager. reg IsterDriver( new oracle .jd be.driver. OracleDriver()); conn = DriverManager.getConnectlon("jdbc: Tid); oracle :thin:@netvistal03: 1521 :soh9i 1",Tname, stmt = conn.createStatement(); rset = stmt.executeQuery("SELECT rset. next(); exa mno= rset.getlnt(" T. * FROMTEACHERT"); Exams"); rset.close() ;stmt.close(); }catch(Exception sqlex){} If( req .getPa rameter("Student") .equals("Enter")) if( req .getParameter("Student") .equals("Delete")) if( req .getParameter("Student") if( req .getParameter("Student") if (surf.equals("Exit")) { .equals("AliQuestion")) SUrf="AI/Question"; .equa Is("Exit")) surf= "Exit"; output= res.getWriter(); res.setContentType("text/html") ; StringBuffer buf=new StringBuffer(); buf.append(" < HTML> < HEAD> <TITLE>"); buf.a ppend(" </TITLE> </HEAD > < BODY>"); surf= "Enter"; surf="Delete"; 25 buf.append("<FORM ACTION= http://netvista METHOD=POST>"); 103 :808 O/Soheb1/ servlet/ AuthenCheck2 buf.append("<H3>Please enter login name and identification number.</H3><BR>"); buf.append("Name: "+"<INPUT TYPE=text NAME=Name><BR>"); buf.append("ID:"+" <INPUT TYPE=text NAME=ID><BR>"); buf.append("<INPUT TYPE=Submit Value=Submit>"); buf.append("<INPUT TYPE=Reset>"); buf.append(" </FORM > </BODY> </HTML>"); output. println( buf. toString(»; output.close() ; ) if (surf.equals("Enter"» { / / For entering new question try { qno= Integer. parseInt( questno); stmt = conn.createStatement(); rset = stmt.executeQuery("INSERT INTO "+ exa m +" (No,Quest,Ans 1,Ans2, Ans3,Ans4,Correct) VALUES(" +qno+", '" + quest+ "', ,It + ans 1 + "','" +a ns2+ "', +ans3+ "', '" +ans4+ "','" + right III ans+"')"); rset.close() ;stmt.close(); stmt = conn.createStatement(); rset = stmt.executeQuery("COMMIT"); output= res.getWriter(); output. println (" <H2 >Inserted Successfully</H2 >"); res. setContentType("text/html"); String Buffer buf=new String Buffer() ; buf.append (" < HTML>< HEAD><TITLE>"); buf.a ppend("Insertion Creation Page"); buf.append (" </TITLE> </HEAD > < BODY>"); buf.append("<FORM ACTION= http://netvista METHOD=POST>"); 103: 8080/Soheb 1/ servlet/ AuthenCheck2 buf.append("<INPUT TYPE=HIDDEN NAME=ID VALUE="+ Tid+">"); buf.append("<INPUT TYPE=HIDDEN NAME=Name VALUE="+ Tname+">"); buf.append("<BR><INPUT TYPE=Submit Value=More>"+" <BR>"); buf.a ppend (" </FORM > </BODY> </HTML> "); output.println( buf.toString(»; output.close() ; 26 rset.closeC) ;stmt.c1oseC); }catchCException { sqlex) output= res.getWriterC); output.printlnC"<H2 >Check following errors</H2>"); output. println Csqlex); res.setContentTypeC"text/html") ; String Buffer buf=new StringBuffer(); buf.appendC" < HTML> < HEAD> <TITLE >"); buf.appendC"Table Creation Page"); buf.append C"</TITLE> </HEAD > < BODY>"); buf.appendC" <FORM ACTION = http://netvista METHOD=POST>"); buf.appendC"<INPUT 103: BOBO/Soheb 1/ servlet/ AuthenCheck 1 TYPE=HIDDEN NAME=ID VALUE="+ Tid+">"); buf.appendC"<INPUT TYPE=HIDDEN NAME=Name VALUE="+ Tname+">"); buf.appendC"<BR><INPUT TYPE=Submit Value=Back>"+"<BR>"); buf.appendC" </FORM > </BODY> </HTML> "); output. printlnCbuf.toStringC»; output.closeC) ; } } if Csurf.equalsC"Delete"» { / / For deletion of question try { qno= Integer. parseIntC questno); output= res.getWriterC); res.setContentTypeC"text/html") ; String Buffer buf=new StringBuffer(); buf.append C"< HTML> < HEAD> <TITLE> "); buf.appendC"Deletion Creation Page"); buf.append C"</TITLE> </HEAD > < BODY>"); buf.appendC" <FORM ACTION = http://netvista METHOD=POST>"); buf.appendC"<INPUT 103: BOBO/Sohebl/servlet/DeleteQuestion TYPE=radio NAME=Answer VALUE=AII>"+"AII"+"<BR>"); forCint j=0;j<4;j++) { buf.appendC" <INPUT TYPE=radio NAME=Answer VALUE=Ans"+Cj+ 1)+" CHECKED>"+"Answer"+Cj+ 1)+"< BR>"); 27 } buf.append("<INPUT TYPE=radio NAME=Answer VAlUE=Correct" +" CHECKED>"+"Corr. Ans."+"<BR>"); buf.append("<BR>New Value for insertion (Default is null)<BR>"); buf.append("<INPUT buf.append("<INPUT buf.append("<INPUT buf.append("<INPUT TYPE=TEXT NAME=New sIZE=80>"); TYPE=HIDDEN NAME=ID VAlUE="+ Tid+">"); TYPE=HIDDEN NAME=Name VAlUE="+ Tname+" >"); TYPE=HIDDEN NAME=questno VAlUE="+questno+">"); buf.append("<INPUT TYPE=HIDDEN NAME=Examname VAlUE="+exam+">"); buf.append(" <BR> < BR> <INPUT TYPE=submit Value= Done>"+"<BR>"); buf.append (" </FORM > </BODY> </HTML>"); output. println(buf. tostring()); output.c1ose() ; }catch(Exception sqlex) { output= res.getWriter(); output.println("<H2>Check following errors</H2 >"); output. println(sqlex); res.setContentType("text/html") ; String Buffer buf=new stringBuffer(); buf.append (" < HTMl> < HEAD><TITLE>"); buf.append("Table Creation Page"); buf.append(" </TiTlE > </HEAD > < BODY>"); buf.append (" < FORM ACTiON = http://netvista 103: 8080/sohebl/servlet/ AuthenCheck2 METHOD=POsT>"); buf.append("<INPUT TYPE=HIDDEN NAME=ID VAlUE="+ Tid+">"); buf.append("<INPUT TYPE=HIDDEN NAME=Name VAlUE="+ Tname+">"); buf.append(" <BR><INPUT TYPE=submit Value=Back>"+"<BR>"); buf.a ppend(" </FORM > </BODY> </HTMl> "); output. println(buf.tostring()); output.close() ; } } if (surf.equals("AIiQuestion")) { try { / / will show all question stmt = conn .createstatement (); rset = stmt.executeQuery("select output= res.getWriter(); * FROM"+exam+" where No<lOOOO"); 28 res.setContentType("text/html") ; StringBuffer buf=new StringBuffer(); buf.append(" < HTML>< HEAD><TITLE >"); buf.append("Student Information Page"); buf.a ppend(" </TITLE> </HEAD > < BODY>"); buf.append(" <FORM ACTION= http://netvista METHOD=POST>"); while (rset.next()) { String temp=""; 103: 8080/Soheb 1/servlet/ AuthenCheck2 buf.append("Q" + rset.getInt( 1)+") "); temp= rset.getString (2); if(temp= =null) temp="N/ A"; buf.append (temp+" < BR>"); for(int i=3;i<=6;i++) { temp=""; temp= rset.getString( i); if(temp= =null) temp="N/ A"; buf.append("Ans"+(i-2)+") } "+temp+" < BR>"); temp= rset.getString(7); if(temp==null) temp="Correct - N/A"; else temp="Correct - Ans"+temp; buf.append (temp+" < BR>"); buf.append(" <BR>"); } buf.append("<INPUT TYPE=HIDDEN NAME=ID VALUE="+ Tid+">"); buf.append("<INPUT TYPE=HIDDEN NAME=Name VALUE="+ Tname+">"); buf.append(" <BR> <BR><INPUT TYPE=Submit Value=Back>"+" <BR>"); buf.a ppend(" </FORM > </BODY > </HTML>"); output. println( buf.toString()); output.c1ose() ; rset.close() ;stmt.close(); }catch(Exception sqlex) { output= res.getWriter(); output.println("<H2>Check output.printin(sqlex) ; following errors</H2>"); res.setContentType("text/html") ; 29 String Buffer buf=new StringBuffer(); buf.append(" < HTML>< HEAD> <TITLE> "); buf.append("Table Creation Page"); buf.append(" </TITLE> </HEAD> < BODY>"); buf.append("<FORM ACTION= http://netvista METHOD=POST>"); 103: 8080/Soheb l/servlet/ AuthenCheck2 buf.append("<INPUT TYPE=HIDDEN NAME=ID VALUE="+ Tid+">"); buf.append("<INPUT TYPE=HIDDEN NAME=Name VALUE="+Tname+">"); buf.append("<BR><INPUT TYPE=Submit Value=Back>"+"<BR>"); buf.append(" </FORM > </BODY> </HTM L>"); output. printin (buf.toString ()); output.close() ; } } } } DeleteQuestion.java import java.sql. *; import javax.swing.*; import oracle.sql. *; import java.io. *; import javax.servlet. *; import javax.servlet.http. *; import java.util. *; import oracle.jdbc.driver. *; // DeleteQuestion will delete and manipulate questions in the Examl, .... ,Examn _ Tables public class DeleteQuestion extends HttpServlet { Connection conn; Statement stmt; ResultSet rset; public void init(ServletConfig config) throws ServletException { super.init( config); } public void doPost(HttpServletRequest IOException { req,HttpServietResponse res) throws 30 PrintWriter output; Cookie cookies[J=null; cookies= req.getCookies(); // Retrieving Teacher Name, ID, Exam Name, Question No etc. String Tname="" ,Tid ="" ,option = "" ,exam =n ull,newval = null; int questno=O; questno= Integer. parseInt( req .getParameter("questno")); option = req .getParameter(" Answer"); //option holds particular columns identification for removing exam = req .getParameter("Examna me"); newval = req .getPara meter("New"); try { questno= Integer.parseInt(req .getPara meter("q uestno")); }catch(NumberFormatException e) { output= res.getWriter(); output.println(" <H2>Check following errors</H2>"); output. println (e); res.setContentType("text/html") ; String Buffer buf=new StringBuffer(); buf.append(" < HTML> < HEAD> <TITLE>"); buf.append("Table Creation Page"); buf.a ppend(" </TITLE > </HEAD > < BODY>"); buf.append(" <FORM ACTION =http://netvista METHOD=POST>"); buf.append("<INPUT buf.append("<INPUT 103: 8080/Sohebl/servlet/ AuthenCheck2 TYPE=HIDDEN NAME=ID VALUE="+ Tid+">"); TYPE=HIDDEN NAME=Name VALUE="+ Tname+">"); buf.append("<BR> <INPUT TYPE=Submit Value=Back>"+" buf.append(" </FORM > </BODY > </HTML> "); <BR>"); output. println (buf.toString()); output.close() ; } if (cookiesl =null) { for (int i=O;i<cookies.length;i++) { Cookie cookie = null; cookie=cookies[i] ; if( (cookie.getNa me()) .equals("Tna me")) Tna me=cookie.getValue(); if( (cookie.getName()) .equals("Tid")) Tid =cookie.getValueO; 31 } } if( option.equals("AII"» { / / For deletion of the full record of a particular question try { DriverManager. reg isterDriver( new oracle .jd be.driver. OracleDrive r(» ; conn= DriverManager.getConnection ("jdbc: oracle :thin:@netvista103: Tid); 1521: soh9i 1",Tname, stmt = conn.createStatement(); rset = stmt.executeQuery("DElETE No<10000"); rset.close() ;stmt.close(); FROM"+exam+" WHERENo="+questno+" stmt = conn.createStatement(); rset = stmt.executeQuery("COMMIT"); output= res.getWriter(); output.println("<H2>Deleted found)</H2>"); Successfully (Also shows Deleted when no match res. setContentType( "text/html"); String Buffer buf=new StringBuffer(); buf.a ppend(" < HTMl> < HEAD><TITLE>"); buf.append("Insertion Creation Page"); buf.append (" </TITlE> </HEAD > < BODY>"); buf.append("<FORM ACTION= http://netvista METHOD=POST>"); 103: 8080/Soheb 1/ servlet/ AuthenCheck2 buf.append("<INPUT TYPE=HIDDEN NAME=ID VAlUE="+ Tid+" >"); buf.append("<INPUT TYPE=HIDDEN NAME=Name VAlUE="+Tname+">"); buf.append("<BR> <INPUT TYPE=Submit Value=More>"+"< BR>"); buf.append (" </FORM > </BODY > </HTMl>"); output. println( buf.toString(»; output.c1ose() ; rset.close() ;stmt.c1ose() ;conn .close(); }catch(Exception sqlex) { output= res.getWriter(); output.println(" <H2 >Check following errors</H2 >"); output. println(sqlex); res.setContentType("text/html") ; String Buffer buf= new String Buffer(); AND buf.a ppend(" < HTML> < HEAD> <TITLE>"); buf.append("'Table Creation Page"); buf.append(" </TITLE > </HEAD > < BODY>"); buf.append("<FORM ACTION= http://netvista METHOD=POST>"); buf.append("<INPUT 103: BOBO/Soheb l/servlet/ Authen Check2 TYPE=HIDDEN NAME=ID VALUE="+ Tid+">"); buf.append("<INPUT TYPE=HIDDEN NAME=Name VALUE="+ Tname+">"); buf.append("<BR> <INPUT TYPE=Submit Value=Back>"+"<BR>"); buf.append (" </FORM > </BODY > </HTM L>"); output. println( buf.toString()); output.close(); } } else { try { / / For deletion based on user option DriverManager. registerDriver(new conn = oracle.jdbc.driver.OracleDriver()); DriverManager.getConnection("jdbc: Tid); oracle :thin:@netvista103: 1521 :soh9i 1",Tna me, stmt = conn.createStatement(); rset = stmt.executeQuery("UPDATE "+exam+" SET "+option+"="'+newval+'" WHERE NO="+Questno+" AND No< 10000"); rset.close() ;stmt.close(); stmt = conn.createStatement(); rset = stmt.executeQuery("COMMIT"); output= res.getWriter(); output.println("<H2>Deleted Successfully (Also shows Deleted when no match found)</H2>"); res. setContentType( "text/html") ; StringBuffer buf=new StringBuffer(); buf.append(" < HTML> < HEAD> <TITLE>"); buf.append("Insertion Creation Page"); buf.append (" </TITLE> </HEAD> < BODY>"); buf.append(" <FORM ACTION= http://netvista 103: BOBO/Soheb1/servlet/ AuthenCheck2 METHOD=POST>"); buf.append("<INPUT TYPE=HIDDEN NAME=ID VALUE="+ Tid+">"); buf.append("<INPUT TYPE=HIDDEN NAME=Name VALUE="+ Tname+">"); 33 buf.append(" <BR> <INPUT TYPE=submit Value=More>"+"< BR>"); buf.a ppend(" </FORM > </BODY> </HTML>"); output. printl n(buf.tostring()); output.close() ; rset.close() ;stmt.close(); }catch(Exception sqlex) { output= res.getWriter(); output.println(" <H2>Check following errors</H2 >"); output. pnntln(sqlex); res.setContentType( "text/html"); String Buffer buf=new stringBuffer(); buf.a ppend(" < HTML> < HEAD><TITLE>"); buf.append("Table Creation Page"); buf.append(" </TITLE> </HEAD > < BODY>"); buf.append("<FORM ACTION=http://netvista 103: 8080/soheb1/servlet/ AuthenCheck2 METHOD=POsT>"); buf.append("<INPUT TYPE=HIDDEN NAME=ID VALUE="+ Tid+">"); buf.append("<INPUT TYPE=HIDDEN NAME=Name VALUE="+ Tname+">"); buf.append(" <BR><INPUT TYPE=submit Value=Back>"+" <BR>"); buf.append (" </FORM > </BODY> </HTML>"); output. println( buf.tostring()); output.close() ; } } } } 34 Module 4 Codes for giving and evaluating examinations exam.html <HTMl> <HEAD> <TITLE> lOGIN </TITlE> </HEAD > < BODY> < FORM ACTION= http://ahmed :8080/Sohebl/servlet/loginCheck METHOD=POST> <PRE> Name: <INPUT TYPE=text NAME=Name> 10: <INPUT TYPE=text NAME=ID> </PRE> <INPUT TYPE=SUBMIT value=Submit> <INPUT TYPE=reset> </FORM> </BODY> </HTMl> LoginCheck.java import java.io. *; import javax.servlet. *; import javax.servleLhttp. *; import java.sql. *; / /loginCheck will check for valid user in the database public class loginCheck extends HttpServlet { Connection c; Statement s; ResultSet rs; public void init(ServletConfig config) throws ServletException { super.init( config); } public void doPost(HttpServletRequest Serv Iet Excepti on, 10Excepti 0 n { req,HttpServletResponse res) throws 35 int i=O,exams; PrintWriter output; String name=tI",id=""; name= req .getParameter("Name"); if(name==null) name=name+"@"; id = req .getParameter("ID"); if(id==null) id=id+"@"; String stl ,st2; rs=null; try { DriverManager. registerDriver (new oracie.jd bc.driver.OracieDriver()); c = DriverManager.getConnection("jdbc: oracle :thin:@netvista103: 1521: soh9i 1", "scott" ,"tiger"); s= c.createSta tement( ResuItSet. TYPE_SCROLL_SENSITIVE,ResultSet. CONCUR_UPDAT ABLE); rs=s.executeQuery("Select }catch(Exception sqlex) { NAME,ID from Student"); output= res.getWriter(); res.setContentType("text/html") output.println(" ; <H2>Check following errors</H2>"); output. println(sqiex); output.close() ; } //start try of Block-1 { rS.next(); / /start of Block-2 /* variable i will hold the value whether a match is found or not. name and id variable will read user's name and id. Every record in the database will be checked. If any record matches looping will be terminated. */ outer: do { stl =rs.getString("ID"); st2 = rS.getString("NAME"); / /name and id cookies will carry name and id of an user. if (stl.equals(id) { && st2.equals(name)) 36 Cookie c1=new Cookie( 'name",name); c1.setMaxAge( -10); Cookie c2=new Cookie("id",id); c2.setMaxAge( -10); res.addCookie(c1) ; res.addCookie(c2) ; i=l; break outer; } }while( rs. next()); Ilend of Block-2 Iistart of Block-3 I*if user match is found it check Teacher database to see how many examination is designed for a subject and will give radio button option to choose one. *1 if(i==l) { rS.close(); s.close(); s = c.createSta tement( ResuItSet. TYPE_SCROLL_SENSITIVE, ResultSet. CONCUR_UPDAT ABLE); rs=s.executeQuery("Select rS.next(); Ilexams T. * from Teacher T"); variable will store number of examination designed for a subject. exams= rs.getInt("Exams"); res.setContentType("text/html") ; output= res.getWriter(); String Buffer buf=new StringBuffer(); if (exams>O) { buf.a ppend(" < HTML> < HEAD> <TITLE> "); buf.append("Examination Start Page"); buf.append(" </TITLE> </HEAD> < BODY>"); buf.append(" < FORM ACTION= http://netvista METHOD=POST>"); buf.append("Login 103: 8080/Soheb 1/servlet/GetExam Name: "+name+"<BR>"+"Login buf.append("<H3>Choose for(int j=O ;j<exams;j++) { buf.append("<INPUT ID: "+id+"<BR><BR>"); an Examination from given below.</H3>"); TYPE=radio NAME=ExamName VALUE=Exam"+(j+ 1)+" >"+"Examination"+ (j+ 1)+"<BR>"); . 37 } buf.append("<H4>Press Submit Button to continue.</H4>"+"<BR>"); buf.append("<INPUT TYPE=submit VALUE=Submit>"); buf.a ppend(" </FORM > </BODY> </HTM L>"); output. println( buf.toString(»; output.close() ; } IIIf no examination is designed, following else block will work Ileise Block of Block-3 else { output= res.getWriter(); res.setContentType("text/html") ; buf=new StringBufferO; output.println("<H2>No examination for you</H2>"); output.close() ; } } I lend of Block-3 IIIf no match found for name and id in the database work following else block will Ileise Block of Block-2 else { output= res.getWriter(); res.setContentType("text/html") ; String Buffer buf=new StringBufferO; buf.a ppend (" < HTML> < HEAD> <TITLE >"); buf.append(" </TITLE > </HEAD > < BODY>"); buf.append (" < FORMACTION= http://netvista METHOD=POST>"); 103: 8080/Sohebl/servlet/LoginCheck buf.append("<H2>Login failed, Re Enter your login name and !D. </H2><BR> < BR>"): buf.append("Name"+"<INPUT buf.append(" TYPE=text NAME=Name>"+"<BR>"); !D"+"<INPUT TYPE=password NAME=!D>"+"<BR>"); buf.append("<BR>"+"<INPUT buf.append("<INPUT TYPE=reset>"); buf.append (" <I FORM> </BODY> output. println( buf. toString(»; output.close() ; } c.closeO; TYPE=SUBMIT VAlue=Submit>"); </HTML> "); 38 }catch (SQLException sqlex) {System.out. println(sqlex); sqlex. printStackTrace();} Ilend of Block-l } public void destroy() { try { c.close(); }catch(Exception e) {System.err.println("Problem } } closing the database");} GetExam.java import java.io. *; import javax.servlet. *; import javax.servlet.http. *; import java.util. *; import java.sql.*; import java.net. *; import java.applet. *; 1* GetExam will take input from LoginCheck and will give the user no. of question per page option.1t will check for unprepeared examination table, question table without any question and whether user is trying to give a previousely given examination. *j public class GetExam extends HttpServlet { Connection c; Statement s; ResultSet rs; public void init(ServletConfig config) throws ServletException { super.init( config); } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException { PrintWriter output; Cookie cookies[]=null; cookies= req .getCookies(); String name= null,id =n t..1I,nullcheck=null,exa m = null; 39 / /qsno(] will hold the identification of randomely choosen questions. int qsno[]=new int(5],rand=O,rowno=O; //exam variable take users input from LoginCheck exa m= req .getParameter("ExamName"); if (cookies! =null) { for (int i=O;i<cookies.length;i++) { Cookie cookie = null; cookie=cookies(i] ; if( (cookie.getName() .equals("name"» if( (cookie.getName(» } } .equals("id"» name=cookie.getVa lue(); id =cookie.getValue(); / /start of Block-1 / /this block will check wheather user is here without choosing an examination in LoginCheck. if (exam! =null) { try { DriverManager. registerDriver (new oracle.jdbc.driver.OracleDriver(); c = DriverManager.getConnection("jdbc: "tiger"); oracle :thin:@netvista103: 1521: soh9i 1", "scott" I s = c.createStatement( ResuItSet. TYPE_SCROLL_SENSITIVE,ResultSet. CONCUR_UPDAT ABLE); rs=s.executeQuery("Select / /rowno holds no. of rows while(rs.next()) { E.* from "+exam+" rowno++; } / /start of Block-2 if (rowno< =0) { res.setContentType("text/html") output= res.getWriter(); ; String Buffer buf= new String Buffer(); buf.a ppend(" < HTML> < HEAD> <TITLE>"); E"); 40 buf.append("Examination buf.append(" Page"); </TITLE> buf.append("Login </HEAD> Name: "+ id +" < BR >" +exam+" < BODY>"); "+name+"<BR>"+"Login < BR> <BR >"); buf.append(" <H3 >No available buf.append(" </FORM > </BODY> </HTM L>"); output. println(buf.toString output.c1ose() ID: question for this examination. </H3 >"); (); ; } else if (rowno==l) { qsno=new int[l]; qsno[O]=l; } else / /while rowno is more than one { do { rand = (int) (Math .random( )*rowno); }while(rand!=O && rand>=rowno); int I=rand; int m=rand+l; int k=O; qsno=new int[rowno]; try { rs.close() s ;s.c1ose(); = c. createStatement( Resu ItSet. TYPE_SCROLL_SENSITIVE, ABLE); rs=s.executeQuery("Select rs.next() ; }catch (Exception sqlex){sqlex.printStackTrace();} rS.a bsolute(I); do { qsno[k]=I; k++; 1-- ; }while( rS.previous(»; rS.absolute(m) do E.* from "+exam+" ; E"); ResultSet. CONCU R_ UPDAT 41 { qsno(k]=m; k++; m++; }while( rs.next()); } fiend of Block-2 / /qid holds qsno as a String, 50 to send in a cookie String qid=new String(); for(int p=O;p<qsno.length;p++) { qid+=qsno(p]; qid+='a'; } Cookie c2=new Cookie("qid",qid); c2.setMaxAge( -10); //Cookie res.addCookie( c2); }catch(Exception sqlex) { res.setContentType("text/html") ; output= res.getWriter(); StringBuffer buf=new StringBuffer(); buf.append (" < HTMl> < HEAD><TITLE>"); buf.append("Examination Page"); buf.append(" </TITlE> </HEAD> < BODY>"); buf.append("login Name: "+"<BR>"+"login ID: "+ id +" < BR>" + exam+" < BR> <BR>"); buf.append("<H3>No available question for this examination.</H3>"); buf.append(" </FORM > </BODY> </HTMl>"); output.println( buf.toString()); output.close() ; } try { rS.close(); s.close(); s= c.createStatement( ResuItSet. TYPE_SCROll_SENSITIVE, ResuitSet. CONCUR_UPDAT ABLE); rs=s.executeQuery("Select rS.next(); S.* from Student S WHEREID="'+id+""'); /* nullcheck will check wheather the exam has given before from exam column in Student table. 42 check will be done for a particular exam (exam choosen by an student)// examination has every an exam column in Student table. */ nullcheck= rS.getString( exam); }catch(SQLException sqlex) {System. out. println (sqlex); sqlex. printStackTrace();} //nullcheck==null means examination has not given before / /start of Block-3 if (nullcheck==null) { Cookie cl=new Cookie("exam",exam); cl.setMaxAge( -10); //Cookie res.addCookie(cl) ; String rownol=''''+rowno; Cookie c2=new Cookie("rowno" ,rownol); c2.setMaxAge( -10); / /Cookie res.addCookie(c2) ; res.setContentType("text/html") output= res.getWriter(); ; String Buffer buf=new StringBuffer(); buf.a ppend (" < HTML>< HEAD> <TITLE>"); buf.append("Examination Page"); buf.append(" </TITLE> </HEAD> < BODY>"); buf.append(" < FORMACTION= http://netvista METHOD=POST>"); 103 :8080/Sohebl/servlet/GetMessage buf.append("Login Name: "+name+"<BR>"+"Login "+id+" <BR>"+exam+" 10: <BR> <BR>"); buf.append("<H4>Total number of question is "+rowno+"</H4>"); buf.append("<BR>"+"<H3>How many question per page?</H3>"); buf.append("<INPUT TYPE=radio NAME=QperPage VALUE=5>"+"5"+"<BR>"); buf.append("<INPUT TYPE=radio NAME=QperPage VALUE=10 CHECKED>"+" 10"+"<BR>"); buf.append(" <INPUT TYPE=radio NAME=QperPage VALUE=15>"+" 15" +"<BR>"); buf.append("<INPUT TYPE=radio NAME=QperPage VALUE=20 >" +" 20" +" < BR> < BR>"); buf.append("<H3>Press Start button to proceed.</H3>"); buf.append("<INPUT TYPE=Submit VALUE=Start>"); buf.append(" </FORM > </BODY> </HTML>"); output. println(buf.toString()); output.c1ose() ; } else { 43 output= res.getWriter(); String Buffer buf=new StringBuffer(); buf.append (" < HTMl> < HEAD> <TITLE >"); buf.append("Examination Start Page"); buf.a ppend(" </TITlE > </HEAD > < BODY>"); buf.append("login Name: "+name+"<BR>"+"login "+id+ "<BR>"+exam+"<BR> <BR> <H2 >"); ID: buf.append("This exam has been given before, try another."+"<BR>"); buf.append(" </H2 > </BODY> </HTMl>"); output. println (buf. toString()); output.close() ; } / lend of Block-3 } I/else Block of Block-l /* following block will execute if user doesn't choose any exam in loginCheck. It will force an user to choose an examination*1 else { output= res.getWriter(); String Buffer buf=new StringBuffer(); buf.append(" < HTMl> < HEAD> <TITLE> "); buf.append("Examination Start Page"); buf.append(" </TITlE> </HEAD> < BODY>"); buf.append(" < FORMACTION= http://netvista 103: 8080/Soheb l/servlet/loginCheck METHOD=POST>"); buf.append("login Name: "+name+"<BR>"+"login ID: "+id+"<BR><BR><H2>"); buf.append("Please go to prvious pagess and choose an Examination. "+" <BR> <BR>"); buf.append("<INPUT TYPE=HIDDEN NAME=ID VAlUE="+id+">"); buf.append("<INPUT TYPE=HIDDEN NAME=Name VALUE="+name+">"); buf.append("<INPUT TYPE=SUBMIT NAME=button VAlUE=Previous>"); buf.append(" </H2 > </BODY > </HTMl>"); output.println (buf.toString()); output.closeO; } / /End of Block-l } public void destroyO { try { c.c1oseO; 44 }catch(Exception } } e) {System.err.println("Problem closing the database");} GetMessage.java import import import import import import java.io.*; javax.servlet. *; javax.servlet.http. java.util.*; java.sql.*; java.net.*; *; import java.applet. *; /* GetMessage will retrieve information from GetExam regarding question per page. It will initiate some cookies with default vaiue to use in next stages. */ pubiic class GetMessage extends HttpServlet { public void doPost(HttpServletRequest Servl et Excepti on, I OExcepti 0 n { req,HttpServietResponse res) throws PrintWriter output; int rowno=O; String name=null,id=null,exam=null; String qperpage= req .getPara meter("QperPage"); /* qperpage means question per page, exam holds examination name, rowno holds total rowno in a particular exam table */ String qanswerl =""; Cookie cookies[J=null; cookies= req .getCookies(); if (cookies! =null) { for (int i=O;i<cookies.length;i++) { Cookie cookie = null; cookie=cookies[i] ; if( (cookie.getName()) .equals("name")) name =cookie.getValue(); if( (cookie.getName()) .equals("id")) id =cookie.getValue(); if( (cookie.getName()) .equals("exam")) exam =cookie.getValue(); if( (cookie.getName() ).equals(" rowno")) rowno= Integer. parselnt( cookie.getValue()); } } 45 Cookie c=new Cookie("qperpage",qperpage); c.setMaxAge( -10); res.addCookie( c); /* qanswer cookie is designed to hold default answer for every question page. In the next stages during opening a page, cookie for that particular page will be searched first. This default cookies for every page will help to initiate the page for the first time */ for(int i=O; i«Integer.parseInt(qperpage)); i+ +) qanswerl + =null+"a"; fort int i=0; i< « rowno/Integer. parseInt( qperpage))+ 1); i+ +) { String cookname="qanswer"+(i+2); Cookie cl =new Cookie(cookname,qanswerl); c l.setMaxAge( -1 0); res.addCookie(cl) ; } /* traceval cookie is designed to identify every page identically. Starting value has given 1, so to get calculation advantages in the next stages.*/ Cookie c2=new Cookie("traceval","I"); c2.setMaxAge( -10); res.addCookie( c2); fiend cookie will hold the ending question number for every page. Cookie c3=new Cookie("end",(""+O)); c3.setMaxAge( -10); res.addCookie(c3) ; res.setCon tentType( "text/html"); output= res.getWriter(); String Buffer buf=new String Buffer(); buf.a ppend(" < HTML>< HEAD> <TITLE>"); buf.append("Examination Start Page"); buf.append(" </TITLE > </HEAD > < BODY>"); buf.append("<FORM ACTION= http://netvista 103: 8080/Sohebl/servlet/GetQuestAns buf.append("Login Name: "+name+"<BR>"+"Login ID: "+ id+" < BR>" +exa m+" < BR> <BR>"); buf.append("<H3>If METHOD=GET> "); you face any problem, talk with your teacher.</H3>"); buf.append("<H4>Press Next Button to start examination.</H4>"+"<BR>"); buf.append("<INPUT TYPE=HIDDEN NAME=TRACEVALVALUE=1 >"); buf.append("<INPUT TYPE=SUBMIT NAME=SURF VALUE=Exit>"); buf.append("<INPUT TYPE=SUBMIT NAME=SURFVALUE=Next>"); buf.append(" </FORM > </BODY> </HTM L>"); output. println (buf. toString()); output.close() ; 46 } } GetQuestAns.java import import import import import java.io. *; javax.servlet. *; javax.servlet.http. java.util. *; java.sql.*; *; import java.net.*; import java.applet. *; import java.text.DecimaIFormat; /* GetQuestAns will generate questions randomly, after submission will calculate score and will update the Student database */ public class GetQuestAns extends HttpServlet { Connection c; Statement s; ResultSet rS,rsl; public void init(ServletConfig config) throws ServletException { super. init( config); } public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException { PrintWriter output; String surf='''',sohlO=''''; int traceval =Integer. parseInt(req .getParameter("TRACEVAL")); if( req .getParameter("SURF") .equals(" Next")) surf="Next"; if( req .getParameter("SURF") .equaIs("Previous")) surf=" Previous"; if( req .getParameter("SURF") .equals("Submit")) surf= "Submit"; if( req .getParameter("SURF") .equa1st"Exit")) surf= "Exit"; //Three conditions may arise, moving next,previous or submitting for score /* traceval will hold identification number of each page, tracevall traceval. is identical to In case of previous butoon traceval for the intended page is always (traceval-2) where traceval is of calling point*/ 47 /* Answer holding cookie for a page has always value(traceval+ 1), cause cookie for any page is generated in the next page, qanswer1 retreive answer value from cookie as string for a particular page and transfer to integer value inqans[]*/ //qans stores answer value from previous page, qid[] holds question identification value for an user / /default cookie of every for a page //start of Block-1 if (surf.equals("Next") page from GetMessage will work when no cookie is found II surf.equals("Previous"» { int traceval1 =traceval; if(surf.equals("Previous"» traceval =traceval-2; String name=nulI,id=nulI,exam=null,qanswer="",qanswer1 =""; String qid 1=n ull,qans1 ,st2,st3,st4,st5,st6; Cookie cookies[]=null; cookies = req .getCookies(); int qperpage=O,rowno=O,stl int qid[]=new int[O]; if (cookiesl =null) { =O,end =O,start=O,qans[]=new int[O]; for (int i=O;i<cookies.length;i++) { Cookie cookie = null; cookie=cookies[i] ; if( (cookie.getName() ).equals("name"» name=cookie.getValue(); if( (cookie.getName() ).equals("id"» id =cookie.getValue(); if( (cookie.getName(» .equals("q perpage"» qperpage= Integer. parseInt( cookie.getValue(»); if( (cookie.getName(» .equals("qid"» qid 1=cookie.getValue(); if( (cookie. 9etNa me(». equaIs(" rowno"» rowno= Integer. parseInt( cookie.getValue(»; if( (cookie.getName(» .equals("exam"» exam=cookie.getValue(); II Get answer cookie for a page first (default from GetMessage may work) String temp=""; temp="qanswer" + (traceval + 1); if( (cookie.getNa me()) .equals(temp» } qanswer1 =cookie.getValue(); } qid=new int[rowno]; I I Transform question serial from string to integer int temp=O; for(int i=O;i<rowno;i++) 48 { String str=""; do { str+ =qid l.charAt(temp); temp++; } while( qid l.charAt(temp)! =' a'); qid[i] =Integer. parselnt(str); temp++; } I I get previous page's answer as string and store in qanswer if (tracevall>l) { int end I = «tracevall-1 )*qperpage)-I; int startl=(endl+I)-qperpage; String tempI =''''; for(int i=startl;i<=endl;i++) { tempI + = req.getParameter("Q"+ (i+ I)); templ+="a"; } qanswer+ =templ; } Ilend holds the end value (serial no.) of question for a particular page Iistart holds the start value (serial no.) of question for a particular page end = (traceval*qperpage)-I; start= (end + I )-qperpage; if( end> = rowno) end = rowno-I; Iino. of answers Is always equal to qperpage for any page Ilretrieve answer cookie value as integer in qans[], if any value null [unchecked] assign 99. qans=new int[qperpage]; temp=O; for(int i=O;i<qperpage;i++) { String strl=""; do { stri + =qanswerl.charAt(temp); temp++; }while(qanswerl.charAt(temp)! ='a'); 49 if (str1.equals("null")) { qans[i]=99; } else { qans[i] = Integer. parseInt(strl); } temp++; } try { DriverManager. registerDriver (new oracle.jdbc.driver.OracieDriver()); c = DriverManager.getConnection("jdbc: "tiger"); oracle :thin:@netvistal03: 1521: soh9i 1", "scott" I s= C. crea teStatemen t( ResuItSet. TYPE_SCROll_SEN SITIVE, ResultSet. CONCUR_UPDAT ABLE); rs=s.executeQuery("Select E.* from "+exam+" //decission to make by (end==rowno-l)for E"); showing submit button if (end==rowno-l) { String cookname="qanswer"Hracevall; Cookie c=new Cookie(cookname,qanswer); c.setMaxAge( -10); res.addCookie(c); res.setContentType("text/html") output= res.getWriter(); ; String Buffer buf=new StringBuffer(); temp=traceval+ 1; buf.a ppend(" < HTMl> < HEAD> <TITLE>"); buf.append("Examination Page"); buf.append (" </TITlE> </HEAD > < BODY>"); buf.append("login Name: "+name+"<BR>"+"login buf.append(" <FORM ACTION=http://netvista int templ=O; 10: "+id+"<BR>"+"<BR>"); 103: 8080/Sohebl/servlet/GetQuestAns for(int i=start;i<=end;i++) { String checkl=" ",check2=" ",check3=" ",check4=" "; METHOD=GET>"); 50 if (qans[temp1]>0 && qans[temp1]<S) { if(qans[temp1]= = 1) check1 =check1 + "CHECKED"; if(qans[temp1]= if(qans[temp1]= =2) check2=check2+"CHECKED"; =3) check3=check3+"CHECKED"; if(qans[temp1 ]==4) check4=check4+ "CHECKED"; } rS.absolute( qid [i]); stl =rs.getInt(" No"); st2 =rs.getString("Quest"); st3 = rs.getString("Ans1 "); st4=rs.getString ("Ans2"); stS = rs.getString("Ans3"); st6=rs.getString("Ans4") ; if(st2 = = null)st2 = "Unassigned"; if(st3 = = null )st3= "Unassigned"; if(st4= =null)st4="Unassigned"; if(stS = = null )stS = "Unassigned"; if(st6= =null)st6="Unassigned"; buf.append("Q"+(i+ buf.append("<INPUT 1)+". "+st2+"<BR>"); TYPE=radio NAME="+ "Q"+ (i+ 1)+" VALUE=" +" 1"+check1 +" >" +st3+" < BR>"); buf.append("<INPUT TYPE=radio NAME=" +"Q"+(i+ 1)+" VALUE=" +" 2" + check2+" >" +st4+" < BR>"); buf.append(" <INPUT TYPE=radio NAME="+"Q"+(i+ 1)+" VALUE=" + "3" +check3+" >" +stS +" < BR>"); buf.append("<INPUT TYPE=radio NAME="+"Q"+(i+1)+" VALUE=" + "4" +check4+" >" +st6+" < BR> < BR>"); temp1++; } buf.append("<INPUT TYPE=HIDDEN NAME=TRACEVALVALUE="+temp+">"); / /for the first page you don't need to show previos button if(tracevall = 1) buf.append("<INPUT TYPE=SUBMIT NAME=SURF VALUE=Previous>") ; buf.append("<INPUT TYPE=SUBMIT NAME=SURF VALUE=Submit>"); buf.append (" </FORM > </BODY > </HTML>"); output. println( buf.toString(»; output.close() ; } else { 51 String cookname="qanswer"+tracevaI1; Cookie c=new Cookie(cookname,qanswer); c.setMaxAge( -10); res.addCookie( c); Cookie c1=new Cookie("end",(""+(end+1))); c1.setMaxAge( -10); res.addCookie(c1) ; temp=traceval+ 1; res.setContentType("text/html") ; output= res.getWriter(); StringBuffer buf=new StringBuffer(); buf.a ppend(" < HTML>< HEAD><TITLE>"); buf.append("Examination Page"); buf.append(" </TITLE > </HEAD> < BODY>"); buf.append("Login Name: "+name+"<BR>"+"Login ID: "+ id +" < BR>" + exa m+" < BR> "); buf.append("<FORM ACTION= http://netvista 103: 8080/Sohebl/servlet/GetQuestAns int temp1=0; for(int i=start;i<=end;i++) { String check1=" ",check2=" ",check3=" ",check4=" "; if (qans[temp1]>0 && qans[temp1]<S) { if(qans[temp1]= = 1) check1 =check1 +"CHECKED"; if(qans[temp1]= =2) check2=check2+ "CHECKED"; if(qans[temp1]= if(qans[temp1]= =3) check3=check3+"CHECKED"; =4) check4=check4+ "CHECKED"; } rs.a bsolute( qid [i]); stl = rs.getInt("No"); st2=rs.getString ("Quest"); st3=rs.getString(" Ans1"); st4=rs.getString("Ans2") ; stS = rs.getString("Ans3"); st6= rs.getString(" Ans4"); if(st2 = = null )st2 = "Unassigned"; if(st3 = = null)st3 =" Unassigned"; if(st4= =null)st4="Unassigned"; if(stS= =null)stS="Unassigned"; if(st6= =null)st6= "Unassigned"; buf.append("Q"+(i+ 1)+". "+st2+" <BR>"); METHOD=GET>"); 52 buf.append(" <INPUT TYPE=radio NAME="+"Q"+(i+ 1)+" VALUE=" +" 1" +checkl +" >" +st3+" < BR>"); buf.append(" <INPUT TYPE=radio NAME="+"Q"+(i+ 1)+" VALUE=" +" 2" +check2 +" >" +st4+" < BR>"); buf.append(" <INPUT TYPE=radio NAME="+"Q"+(i+ 1)+" VALUE=" +" 3" + check3 +" >" +st5+" < BR>"); buf.append("<INPUT TYPE=radio NAME="+"Q"+(i+l)+" VALUE=" + "4" +check4+" >" +st6+" < BR> < BR>"); templ++; } buf.append("<INPUT TYPE=HIDDEN NAME=TRACEVALVALUE="+temp+">"); if(traceval = 1) buf.append(" <INPUT TYPE=SUBMIT NAME=SURF l VALUE=Previous>") ; buf.append("<INPUT TYPE=SUBMIT NAME=SURF VALUE=Next>"); buf.a ppend(" </FORM > </BODY> </HTM L>"); output. println(buf.toString(»; output.c1ose() ; } }catch (SQLException sqlex) {System.out. println(sqlex) ;sqlex. printStackTrace();} } //Block-l's else portion starts, used to calculate score else if (surf.equals("Submit"» { String st2=null,st7=null,check=null; double mark=O,count=O; int rowno=O,qid[]=new int[O],qperpage=O,end =O,qans[]=new int[O ],stl ,condition =0; String name=null,id=null,exam=null,qid DecimalFormat twodigit=new output= res.getWriter(); 1=null,qanswer="",cnl DecimaIFormat("O.OO"); Cookie cookies[]=null; cookies= req .getCookies(); if (cookiesl =null) { for (int i=O;i<cookies.length;i++) { Cookie cookie = null; cookie=cookies[i] ; if( (cookie.getName(» .equals("name"» if( (cookie.getName() .equals("id"» if( (cookie.getName() .equals("exam"» if( (cookie.getName().equals("qid"» name=cookie.getValue(); id =cookie.getValue(); exam=cookie.getValue(); qid 1=cookie.getValue(); =null; ~' .) if( (cookie.getName() ).equals("rowno")) rowno= Integer.parseInt( cookie.getVaiue()); if( (cookie.getName() ).equals("end")) end= Integer. parseInt( cookie.getValue()); if( (cookie.getName()) .equals("q perpage")) qperpage= Integer. parseInt( cookie.getVal ue()); } } int page=(int)Math.ceil(rowno/qperpage)+ 1; / /join cookies for all pages as qanswer for(int j=O;j< =page;j++) { cnl=null; en 1="qanswer"; cnl=cnl+j; Cookie cookiesl[]=null; cookiesl =req.getCookies(); if (cookiesl!=null) { for (int k=O;k<cookies1.length;k++) { Cookie cookiel = null; cookiel =cookiesl [k]; if( (cookiel.getName()).equals(cnl)) } } } res.setContentType("text/html") ; StringBuffer buf=new StringBuffer(); //rs=null; //rsl=null; qid=new int[rowno]; qans=new int[rowno]; int temp=O; //get question serial ID for(int i=O;i<rowno;i++) { String str= ''''; do { str+ =qid 1.charAt(temp); temp++; }while(qidl.charAt(temp)! ='a'); qanswer+ =cookiel.getValue(); 54 qid [i] =Integer, parseInt(str); temp++; } / /get answer value from the last page and join them with qanswer String str= ""; for(int i=end;i<rowno;i++) { str+ =req.getParameter("Q"+(i+ 1»; str+="a"; } qanswer+ =str; //get all answer values as integer in qans[i] temp=O; for(int i=O;i<rowno;i++) { String strl = ""; do { strl + =qa nswer.charAt(temp); temp++; }while(qanswer.charAt(temp)! ='a'); if (strl.equals("null"» { qans[i]=99; } else { qa ns[i] = Integer. parseInt(strl); } temp++; } try { rs,c1ose(); s.c1ose(); s = c.createSta tement( ResuItSet.TYPE_SCROLL_SENSITIVE, ResultSet, CONCUR_UPDAT ABLE); rs=s,executeQuery("Select rs,next(); }catch(Exception { sqlex) output= res.getWriter(); E.* from "+exam+" E"); 55 res.setContentType("text/html") ; output.println(" <H2>Check following errorsl_l output. println (sqlex); output.c1ose(); } </H2>"); 1* get the correct answer no. using question ID (qid[]) from particular examination table and compare with value in qans[]*1 try { for(int i=O;i<rowno;i++) { rs.absolute( qid [i]); st2 =rs.getString("CORRECT"); if(st2 = = null)st2 ="110"; if(st2.equalslgnoreCase(""+qans[i])) } rsl=s.executeQuery("Select rsl.next(); mark=mark+ 1; S.* from Student S WHEREID="'+id+'''''); Ilif st7! =null examination has been given before, so user can't give this exam again st7=rsl.getString(exam) if (st7==null) { ; s.executeUpdate("UPDATE student SET "+exam+"="+mark+" ID="'+id+"'"); condition= 1; s.executeQuery("COMMIT") ; } }catch(Exception sqlex) { output= res.getWriter(); res.setContentType("text/html") output.println("<H2>Check output. println(sqlex); output.close() ; } ; following errors2 </H2 >"); Ilcondition==O means examination has been given before if (condition = = 1) { buf.append(" < HTML>< HEAD><TITLE>"); buf.append("Examination Score Page"); buf.append(" </TITLE> </HEAD> < BODY>"); WHERE 56 buf.append("Login Name: "+name+"<BR>"+"Login ID: "+ id+" <BR>" +exam+" < BR> <BR> <H2 >"); double rowno1 =(double)rowno; buf.append("Your Score is: "+mark+" in "+rowno1+"<BR>"); buf.append("Percentage is: "+twodigiUormat( buf.append(" </H2 > </BODY> </HTMl>"); output. println(buf.toString()); output.close() ; (mark/rowno)* 100)+ "%"); } else { buf.append (" < HTML>< HEAD><TITLE>"); buf.append("Examination Score Page"); buf.append(" </TITLE> </HEAD > < BODY>"); buf.append("Login Name: "+name+"<BR>"+"Login ID: "+id+"<BR>"+exam+" "+"<BR><H2>"); buf.append("We can't accept your score, this exam has been given before. "+" <BR>"); buf.append(" </H2 > </BODY> </HTML>"); output. println (buf.toString ()); output.close() ; } } //Block-1's else portion start, if user wants to exit else { res.setContentType("text/html") output= res.getWriter(); ; StringBuffer buf=new StringBuffer(); buf.append (" < HTML>< HEAD><TITLE> "); buf.append("Examination Exit Page"); buf.append(" </TITLE> </HEAD> < BODY>"); buf.append("Good Bye, Give the examination later."+"<BR>"); buf.append(" </H2 > </BODY> </HTM L>"); output. printl n(buf. toString ()); output.close() ; } / /End of Block1 } public void destroy() { try { c.close() ; 57 }catch(Exception e) {System.err.println("Problem } } closing the database");}