exam.txt

Upload: akyadav123

Post on 09-Mar-2016

217 views

Category:

Documents


0 download

DESCRIPTION

EXAM APPLET CODE

TRANSCRIPT

  • 1. EXAM APPLET CODE(This program displayselected subject,questions and result)&(linkto the following programs Evaluate,getlang and getquest javafiles and examapplet,logout html files)/**/import java.io.*;import java.awt.*;import java.awt.event.*;import java.applet.*;import java.util.*;import java.net.*;public class examapplet extends Applet implements ActionListener,Runnable,ItemListener{Thread t=null; Button start=null,next=null,prev=null,submit=null,ok=null,logout=null; CheckboxGroup cbg=null; Checkbox cha=null,chb=null,chc=null,chd=null,che=null; Checkbox choa=null,chob=null,choc=null,chod=null,choe=null; Hashtable ques=null,ans=null; TextArea quest=null; int count=0; Panel textpanel=null,radio=null,check=null,buttons=null; Enumeration keys=null; Object key=null; String keyval=null; Label qno=null,status=null; String selectlang=""; Choice langc=null; Label request=null;public void init(){ setBackground(Color.cyan); ans=new Hashtable(); setLayout(null); qno=new Label(); qno.setBounds(10,10,140,15); add(qno); status=new Label("Time: 00:00:00"); status.setBounds(250,10,400,15); add(status); quest=new TextArea(5,60); quest.setEditable(false); quest.setBounds(10,40,480,140); add(quest); quest.setVisible(false); start=new Button("Start"); start.setBounds(240,240,40,20); add(start); start.addActionListener(this); next=new Button("Next >>"); next.addActionListener(this); prev=new Button("
  • buttons.add(ok); buttons.setBounds(240,240,240,30); add(buttons); buttons.setVisible(false); submit=new Button("Submit"); submit.setBounds(20,240,50,30); add(submit); submit.setVisible(false); submit.addActionListener(this); cbg=new CheckboxGroup(); cha=new Checkbox("A",cbg,true); chb=new Checkbox("B",cbg,false); chc=new Checkbox("C",cbg,false); chd=new Checkbox("D",cbg,false); che=new Checkbox("E",cbg,false); radio=new Panel(); radio.setLayout(new GridLayout(1,5)); radio.add(cha); radio.add(chb); radio.add(chc); radio.add(chd); radio.add(che); radio.setBounds(40,200,420,30); add(radio); radio.setVisible(false); choa=new Checkbox("A"); chob=new Checkbox("B"); choc=new Checkbox("C"); chod=new Checkbox("D"); choe=new Checkbox("E"); check=new Panel(); check.add(choa); check.add(chob); check.add(choc); check.add(chod); check.add(choe); check.setBounds(40,200,420,30); add(check); check.setVisible(false); request=new Label("Please select your subject from the choice list given under."); request.setBounds(20,110,460,20); add(request); t=new Thread(this,"timer"); try { URL url1=new URL(getDocumentBase(),"/servlet/getLang"); URLConnection urc1=url1.openConnection(); ObjectInputStream ois1=new ObjectInputStream(urc1.getInputStream()); String lang=(String)ois1.readObject(); StringTokenizer st=new StringTokenizer(lang,"@"); langc=new Choice(); while(st.hasMoreTokens()) { langc.addItem(st.nextToken()); } ois1.close(); langc.addItemListener(this); langc.setBounds(200,120,100,30);

  • add(langc); }catch(Exception e) { } }public void run(){ int hours=0,minutes=0,seconds=0;while(minutes
  • marksl.setBounds(20,140,100,20); add(marksl); maxgra=new Label("");

    maxgra.setBounds(140,100,200,20); //maxgra.setBackground(Color.blue); add(maxgra); resgra=new Label(""); resgra.setBounds(140,140,((marks*200)/ans.size()),20); //resgra.setBackground(Color.blue); add(resgra); logout=new Button("Logout"); logout.addActionListener(this); logout.setBounds(230,200,40,30); add(logout); } catch(Exception e) { }} public void actionPerformed(ActionEvent ae){ if(ae.getSource()==logout) { AppletContext ac=getAppletContext(); try { ac.showDocument(new URL(getDocumentBase(),"/logout.html")); } catch(Exception e) { } } if(ae.getSource()==start) { try { URL url=new URL(getDocumentBase(),"/servlet/getquest?lang=" + selectlang); URLConnection con=url.openConnection(); ObjectInputStream ois=new ObjectInputStream(con.getInputStream()); ques=(Hashtable)ois.readObject(); buttons.setVisible(true); start.setVisible(false); start=null; langc.setVisible(false); langc=null; request.setVisible(false); request=null; quest.setVisible(true); quest.append("Navigate through the questions with the \nhelp of the buttons"); t.start(); Enumeration e=ques.keys(); while(e.hasMoreElements()) { ans.put((String)e.nextElement(),""); } } catch(Exception e) { } } if(ae.getSource()==submit) {submit(); }

  • if(ae.getSource()==next) { choa.setState(false);cha.setState(false); chob.setState(false);chb.setState(false); choc.setState(false);chc.setState(false); chod.setState(false);chd.setState(false); choe.setState(false);che.setState(false); quest.setText(""); keys=ques.keys(); count++; int i=0; while(iques.size()) { count=ques.size(); } if(count == ques.size()) { submit.setVisible(true); } else { submit.setVisible(false); } if(keys.hasMoreElements()) { key=keys.nextElement(); } i++; } Object obj=ques.get(key); keyval=(String)key; String str=(String)obj; StringTokenizer st=new StringTokenizer(str,"@"); String str1=null; char ch='a'; while(st.hasMoreElements()) { str1=st.nextToken(); if(!str1.equals("null")) { quest.append( str1 + "\n\n" + ch + ") "); che.setVisible(true); ch++; } else { che.setVisible(false); } } if(keyval.charAt(1)=='S' || keyval.charAt(1)=='s') { radio.setVisible(true); check.setVisible(false); } else { radio.setVisible(false); check.setVisible(true); }

  • qno.setText("Question " + count + " of " + ques.size()); } if(ae.getSource()==prev) { quest.setText(""); choa.setState(false);cha.setState(false); chob.setState(false);chb.setState(false); choc.setState(false);chc.setState(false); chod.setState(false);chd.setState(false); choe.setState(false);che.setState(false);

    keys=ques.keys(); if(count

  • } qno.setText("Question " + count + " of " + ques.size()); } if(ae.getSource()==ok) { String ans1="";

    if(keyval.charAt(1)=='S' || keyval.charAt(1)=='s') { Checkbox cb=cbg.getSelectedCheckbox(); if(cb==cha) ans1="a"; if(cb==chb) ans1="b"; if(cb==chc) ans1="c"; if(cb==chd) ans1="d"; if(cb==che) ans1="e"; } else { if(choa.getState()) ans1+="a"; if(chob.getState()) ans1+="b"; if(choc.getState()) ans1+="c"; if(chod.getState()) ans1+="d"; if(choe.getState()) ans1+="e"; } status.setText(ans1); ans.put(keyval,ans1); }}}

    2.GETLANG PROGRAMimport java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;public class getLang extends HttpServlet{Connection con=null;Statement st=null;ResultSet rs=null;public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException{ try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("Jdbc:Odbc:online"); st=con.createStatement(); rs=st.executeQuery("select * from msubjectinfo"); String lang=""; while(rs.next()) { lang+= rs.getString(2) + "@"; } ObjectOutputStream oos=new ObjectOutputStream(res.getOutputStream()); oos.writeObject(lang); } catch(Exception e) { }}

  • }3.GETQUEST PROGRAMimport java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;public class getquest extends HttpServlet{Hashtable ht=null;Connection con=null;Statement st=null;ResultSet rs=null,rs1=null;public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException{ String lang=req.getParameter("lang"); /*try { ObjectInputStream ois=new ObjectInputStream(req.getInputStream()); lang=(String)ois.readObject(); } catch(Exception e) { }*/ String queskey=null,quesvalue=null; ht=new Hashtable(); String code=""; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:online"); st=con.createStatement(); rs1=st.executeQuery("select sub_code from msubjectinfo where sub_title='" + lang + "'"); rs1.next(); //code=rs1.getString(1); rs=st.executeQuery("select * from mquestions where lang='" + rs1.getString(1) + "'"); while(rs.next()) { queskey=rs.getString(1) + rs.getString(2) + rs.getString(3); quesvalue=rs.getString(4) + "@" + rs.getString(5) + "@" + rs.getString(6) + "@" + rs.getString(7) + "@" + rs.getString(8) + "@" + rs.getString(9); ht.put(queskey,quesvalue); } } catch(Exception e) { } OutputStream os=res.getOutputStream(); ObjectOutputStream oos=new ObjectOutputStream(os); oos.writeObject(ht);}}4.EVALUATE PROGRAMimport java.io.*;import java.sql.*;import javax.servlet.*;

  • import javax.servlet.http.*;import java.util.*;public class evaluate extends HttpServlet{Connection con=null;Statement st=null;ResultSet rs=null;public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException{ int count=0; Hashtable ht=null; int size=0; try { ObjectInputStream ois=new ObjectInputStream(req.getInputStream()); ht=(Hashtable)ois.readObject(); size=ht.size(); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("Jdbc:Odbc:online"); st=con.createStatement(); char lang='x',type='y'; int number=0; Enumeration e=ht.keys(); String ans="",key=""; while(e.hasMoreElements()) { key=(String)e.nextElement(); lang=key.charAt(0); type=key.charAt(1); number=Integer.parseInt(key.substring(2)); ans=(String)ht.get(key); rs=st.executeQuery("select answer from mquestions where lang='" + lang + "' and " + "questype='" + type + "' and quesno=" + number); rs.next(); if(ans.equals(rs.getString(1))) count++; } ObjectOutputStream oos=new ObjectOutputStream(res.getOutputStream()); String str=String.valueOf(count); oos.writeObject(str); } catch(Exception e) { }}public void doPost(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException{ doGet(req,res);}}5.SUBJECTS ADDING PROGRAM(This programconsists Sadd javafile)import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;import java.net.*;public class ASubja extends HttpServlet

  • { public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); res.setContentType("text/html"); out.println(""); out.println(""); out.println("function f1()"); out.println("{"); out.println("window.location.href='http://localhost:8080/atsubjects.html';"); out.println("}"); out.println("function f3(fr)"); out.println("{"); out.println("if(fr.v1.value==''){"); out.println("alert('Please enter The Subject Code')"); out.println("fr.v1.focus()"); out.println("}"); out.println("if(fr.v1.value.length>1){"); out.println("alert('Sorry! U Have to enter a Single character only.')"); out.println("fr.v1.focus()"); out.println("}"); out.println("}"); out.println("function f4(fr)"); out.println("{"); out.println("if(fr.v2.value==''){"); out.println("alert('Please enter the Subject Title')"); out.println("fr.v2.focus()"); out.println("}"); out.println("if(fr.v2.value.length>25){"); out.println("alert(\"Sorry! The entered data is out of RANGE\")"); out.println("fr.v2.focus()"); out.println("}"); out.println("}"); out.println(""); out.println(""); out.println(""); out.println("SUBJECT ENTRY"); out.println("Enter Subject Code "); out.println("Enter Subject Title "); out.println(" "); out.println(""); } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { doGet(req,res); }}6.SUBJECT ADDED SUCCESSFULLY PROGRAMimport java.io.*;import java.sql.*;import java.util.*;

  • import javax.servlet.*;import javax.servlet.http.*;public class Sadd extends HttpServlet{ ResultSet rs; Statement st1; PrintWriter pw ; public void doGet(HttpServletRequest req,HttpServletResponse res)

    throws ServletException,IOException{ doPost(req,res);

    }public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{ int i=0;

    try{

    pw = res.getWriter();Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con = DriverManager.getConnection("jdbc:odbc:online");System.out.println("connected");Statement st= con.createStatement();st1= con.createStatement();res.setContentType("text/html");String temp=req.getParameter("v1");String code=temp.toUpperCase();String name=req.getParameter("v2");

    String query1="select sub_code from msubjectinfo";ResultSet rs1=st.executeQuery(query1);while(rs1.next()){ String cc1=rs1.getString(1); if(code.equalsIgnoreCase(cc1))

    {i=1; }

    } if(i==1)

    {pw.println("");pw.println("");pw.println("exist");pw.println("");

    pw.println("");pw.println("");pw.println("");pw.println("");pw.println(""); pw.println("This Subject code");pw.println(""+code+"");pw.println("is already registered");pw.println("");pw.println("Please change your Subject Code");pw.println("");

    pw.println("");pw.println("Back..");pw.println("");

    pw.println(""); }

  • else { int i1=st.executeUpdate("insert into msubjectinfo values('"+code+"','"+n

    ame+"')"); pw.println(""); pw.println(""); pw.println("Record inserted Successfully"); pw.println("Back.."); pw.println(""); st.close(); con.close(); pw.close(); }}catch(Exception e) { pw.println(e.toString()); } } }

    7.SUBJECTS ARE UPDATED(This programincludes supdate javafile)import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;import java.net.*;public class ASubju extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); res.setContentType("text/html"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:online","scott","tiger"); Statement st=c.createStatement(); ResultSet rs=st.executeQuery("select * from msubjectinfo"); out.println(""); out.println("function f1()"); out.println("{"); out.println("window.location.href='http://localhost:8080/atsubjects.html';"); out.println("}"); out.println("function f3()"); out.println("{"); out.println("alert('Modifications...');"); out.println("}"); out.println(""); String msr; out.println("UPDATION"); out.println(""); out.println(""); out.println("Choose Subject Code");

  • while(rs.next()) { msr=rs.getString(1); out.println("" + msr); } out.println(""); out.println("Subject Title"); out.println(""); out.println("&nbsp&nbsp"); out.println(""); rs.close(); st.close(); c.close(); } catch(Exception e) { out.println(e.toString()); } } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { doGet(req,res); }}8.UPDATED SUCCESSFULLY PROGRAMimport java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.net.*;import java.sql.*;public class Supdate extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); res.setContentType("text/html"); String code,name; code=req.getParameter("code"); name=req.getParameter("title"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:online"); Statement st=c.createStatement(); int i=st.executeUpdate("update msubjectinfo set sub_title='"+ name +"' where sub_code='"+code+"' "); out.println(""); out.println("Record Updated Sucessfully"); out.println("Back.."); st.close(); c.close(); } catch(Exception e) {

  • out.println(e.toString()); } } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { doGet(req,res); }}9.SUBJECTS DELETED(This programincludes sdelete javafile)import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;import java.net.*;public class ASubjd extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); res.setContentType("text/html"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:online","scott","tiger"); Statement st=c.createStatement(); ResultSet rs=st.executeQuery("select * from msubjectinfo"); out.println(""); out.println(""); out.println("function f1()"); out.println("{"); out.println("window.location.href='http://localhost:8080/atsubjects.html';"); out.println("}"); out.println(""); String code; out.println(""); out.println(""); out.println("DELETION"); out.println("Choose Subject Code "); while(rs.next()) { code=rs.getString(1); out.println("" + code); } out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println("Warning: If U delete the Subject Code"); out.println("then the corresponding RECORDS will also be DELETED.");

  • out.println(""); rs.close(); st.close(); c.close(); } catch(Exception e) { out.println(e.toString()); } } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { doGet(req,res); }}10.SDELETE PROGRAMimport java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.net.*;import java.sql.*;public class Sdelete extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); res.setContentType("text/html"); String code; code=req.getParameter("code"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:online"); Statement st=c.createStatement(); int i=st.executeUpdate("delete from msubjectinfo where sub_code='"+ code +"'"); int j=st.executeUpdate("delete from mquestions where lang='" + code +"'"); out.println(""); out.println(""); out.println(""); out.println("The subject code " + code +"");

    out.println("is Deleted.."); out.println(""); out.println(""+j + "");

    out.println("Records are Deleted from Questions Database."); out.println("Back.."); out.println(""); st.close(); c.close(); } catch(Exception e) {

  • out.println(e.toString()); } } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { doGet(req,res); }}11.SUBJECT LISTimport java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;import java.net.*;public class ASubjl extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); res.setContentType("text/html"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:online","scott","tiger"); Statement st=c.createStatement(); ResultSet rs=st.executeQuery("select * from msubjectinfo"); out.println(""); out.println(""); out.println("function f1()"); out.println("{"); out.println("window.location.href='http://localhost:8080/atsubjects.html';"); out.println("}"); out.println(""); String code,name; out.println("");

    out.println(""); out.println(""); out.println("SUBJECT LIST"); out.println("Subject codeSubject Title"); while(rs.next()) { code=rs.getString(1); name=rs.getString(2); out.println("" + code + "" + name + ""); } out.println(""); out.println(""); out.println(""); out.println(""); rs.close(); st.close();

  • c.close(); } catch(Exception e) { out.println(e.toString()); } } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { doGet(req,res); }}12.QUESTIONS ADD(This program includes Qadd javafile)import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;import java.net.*;import java.util.Vector;public class AQuesa extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); res.setContentType("text/html"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:online"); Statement st=c.createStatement(); out.println(""); out.println(""); out.println("function f1()"); out.println("{"); out.println("window.location.href='http://localhost:8080/atquestions.html';"); out.println("}"); out.println(""); out.println(""); out.println(""); ResultSet rs=st.executeQuery("select max(quesno) from mquestions"); if(rs!=null) { rs.next(); } String str=rs.getString(1); int number=Integer.parseInt(str); ResultSet rs1=st.executeQuery("select * from msubjectinfo"); out.println("ADDITION
    Question no : "); while(rs1.next()) { out.println("" + rs1.getString(2)); } out.println("");

  • out.println("SingleMultiple"); out.println(""); out.println("Enter Question "); out.println("Enter Choice 1 "); out.println("Enter Choice 2 "); out.println("Enter Choice 3 "); out.println("Enter Choice 4 "); out.println("Enter Choice 5 "); out.println("Enter Answer "); out.println(""); out.println(" "); out.println(""); } catch(Exception e) { out.println(e.toString()); } }}13.QADD PROGRAMimport java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.net.*;import java.sql.*;public class Qadd extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { res.setContentType("text/html"); PrintWriter out=res.getWriter(); String lang=req.getParameter("lan"); String type=req.getParameter("type"); int num=Integer.parseInt(req.getParameter("number")); String question=req.getParameter("quest"); String ch1=req.getParameter("ch1"); String ch2=req.getParameter("ch2"); String ch3=req.getParameter("ch3"); String ch4=req.getParameter("ch4"); String ch5=req.getParameter("ch5"); String ans=req.getParameter("answer"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:online"); Statement st=c.createStatement(); int n=st.executeUpdate("insert into mquestions values('" + lang + "','" + type + "'," + num + ",'" + question + "','" + ch1 + "','" + ch2 +

  • "','" + ch3 + "','" + ch4 + "','" + ch5 + "','" + ans + "')"); out.println(""); out.println("Record inserted Successfully"); out.println("Back.."); out.println(""); st.close(); c.close(); } catch(Exception e) { out.println(e.toString()); } } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { doGet(req,res); }}14.QUESTIONS UPDATATION(Thisprogram includes AQuesuc javafile)import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;import java.net.*;public class AQuesu extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); res.setContentType("text/html"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:online"); Statement st=c.createStatement(); ResultSet rs=st.executeQuery("select * from msubjectinfo"); out.println(""); out.println(""); out.println("function f1()"); out.println("{"); out.println("window.location.href='http://localhost:8080/atquestions.html';"); out.println("}"); out.println(""); out.println(""); out.println(""); out.println(""); out.println("Choose Subject Code "); String val="",caption=""; while(rs.next()) { val=rs.getString(1); caption=rs.getString(2); out.println("" +caption);

  • } out.println(""); out.println(" "); out.println(""); rs.close(); st.close(); c.close(); } catch(Exception e) { out.println(e.toString()); } } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { doGet(req,res); } }15.AQuesuc programimport java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;import java.net.*;public class AQuesuc extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); res.setContentType("text/html"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:online"); Statement st=c.createStatement(); String mcode=req.getParameter("code"); HttpSession hs=req.getSession(true); hs.putValue("msrcode",mcode); ResultSet rs=st.executeQuery("select * from mquestions where lang='"+mcode+"' "); out.println(""); out.println(""); out.println("function f1()"); out.println("{"); out.println("window.location.href=\"http://localhost:8080/servlet/AQuesu.class\";"); out.println("}"); out.println(""); out.println(""); out.println(""); out.println(""); out.println("Choose Question Id "); String val="",lan="",type=""; while(rs.next()) { val=rs.getString(3); type=rs.getString(2);

  • lan=rs.getString(1); out.println("" + lan + type + val); } out.println(""); out.println(" "); out.println(""); rs.close(); st.close(); c.close(); } catch(Exception e) { out.println(e.toString()); } } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { doGet(req,res); }}16 AQUESUCU PROGRAMimport java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;import java.net.*;public class AQuesucu extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); res.setContentType("text/html"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:online"); Statement st=c.createStatement(); String questno=req.getParameter("pcode"); char lan=questno.charAt(0); char type=questno.charAt(1); int val=Integer.parseInt(questno.substring(2)); ResultSet rs=st.executeQuery("select * from mquestions where lang='" + lan + "' and questype='" + type + "' and quesno=" + val); out.println(""); out.println(""); out.println("function f1()"); out.println("{"); out.println("window.location.href=\"http://localhost:8080/servlet/AQuesu.class\";"); out.println("}"); out.println(""); out.println(""); out.println(""); out.println("");

  • rs.next(); out.println("UPDATIONQuestion no: "); out.println("Question is "+ rs.getString(4)+""); out.println("Choice1 is "+ rs.getString(5)+""); out.println("Choice2 is "+ rs.getString(6)+""); out.println("Choice3 is "+ rs.getString(7)+""); out.println("Choice4 is "+ rs.getString(8)+""); out.println("Choice5 is "+ rs.getString(9)+""); out.println("Answer is "); rs.close(); st.close(); c.close(); out.println(""); out.println(""); out.println(""); out.println(""); } catch(Exception e) { out.println(e.toString()); } } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { doGet(req,res); }}17 AQUESUCUC programimport java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.net.*;import java.sql.*;public class AQuesucuc extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); res.setContentType("text/html"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:online"); Statement st=c.createStatement(); String questno=req.getParameter("lang"); char lan=questno.charAt(0); char type=questno.charAt(1); int val=Integer.parseInt(questno.substring(2)); String quest=req.getParameter("quest"); String ch1=req.getParameter("ch1"); String ch2=req.getParameter("ch2"); String ch3=req.getParameter("ch3"); String ch4=req.getParameter("ch4");

  • String ch5=req.getParameter("ch5"); String ans=req.getParameter("ans"); int i=st.executeUpdate("update mquestions set question='"+quest+"',choice1='"+ch1+"',choice2='"+ch2+ "',choice3='"+ch3+"',choice4='"+ch4+"',choice5='"+ch5+"',answer='"+ans+"' where (lang='" + lan + "' and questype='" + type + "' and quesno=" + val + ")"); out.println(""); out.println(""); out.println("Record Updated Sucessfully"); out.println(""); out.println("Back.."); st.close(); c.close(); } catch(Exception e) { out.println(e.toString()); } } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { doGet(req,res); }}18.QUESTIONS DELETED(This program includesAQuesdc java file)import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;import java.net.*;public class AQuesd extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); res.setContentType("text/html"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:online"); Statement st=c.createStatement(); ResultSet rs=st.executeQuery("select * from msubjectinfo"); out.println(""); out.println(""); out.println("function f1()"); out.println("{"); out.println("window.location.href='http://localhost:8080/atquestions.html';"); out.println("}"); out.println(""); out.println(""); out.println(""); out.println(""); out.println("Choose Subject Code "); String val="",caption=""; while(rs.next())

  • { val=rs.getString(1); caption=rs.getString(2); out.println("" +caption); } out.println(""); out.println(" "); out.println(""); rs.close(); st.close(); c.close(); } catch(Exception e) { out.println(e.toString()); } } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { doGet(req,res); } }19 AQUESDC programimport java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;import java.net.*;public class AQuesdc extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); res.setContentType("text/html"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:online"); Statement st=c.createStatement(); String mcode=req.getParameter("code"); HttpSession hs=req.getSession(true); hs.putValue("msrcode",mcode); ResultSet rs=st.executeQuery("select * from mquestions where lang='"+mcode+"' "); out.println(""); out.println(""); out.println("function f1()"); out.println("{"); out.println("window.location.href=\"http://localhost:8080/servlet/AQuesu.class\";"); out.println("}"); out.println(""); out.println(""); out.println(""); out.println(""); out.println("Choose Question Id "); String val="",lan="",type=""; while(rs.next()) { val=rs.getString(3);

  • type=rs.getString(2); lan=rs.getString(1); out.println("" + lan + type + val); } out.println(""); out.println(" "); out.println(""); rs.close(); st.close(); c.close(); } catch(Exception e) { out.println(e.toString()); } } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { doGet(req,res); }}20 AQUESUCD PROGRAMimport java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;import java.net.*;public class AQuesucd extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); res.setContentType("text/html"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:online"); Statement st=c.createStatement(); String questno=req.getParameter("pcode"); char lan=questno.charAt(0); char type=questno.charAt(1); int val=Integer.parseInt(questno.substring(2)); int i=st.executeUpdate("delete from mquestions where lang='" + lan + "' and questype='" + type + "' and quesno=" + val); out.println(""); out.println(""); out.println(""); out.println("Record " + val +" is Deleted Successfully"); out.println("Back.."); out.println(""); st.close(); c.close(); out.println(""); out.println(""); } catch(Exception e) { out.println(e.toString());

  • } } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { doGet(req,res); }}21 USERS ADDING PROGRAMimport java.io.*;import java.sql.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;public class AUsers extends HttpServlet{ ResultSet rs; Statement st1;

    PrintWriter pw ; public void doGet(HttpServletRequest req,HttpServletResponse res)

    throws ServletException,IOException{ doPost(req,res);

    }public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{

    int i=0;try{pw= res.getWriter();Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con = DriverManager.getConnection("jdbc:odbc:online");

    System.out.println("connected");Statement st= con.createStatement();st1= con.createStatement();res.setContentType("text/html");String s1=req.getParameter("aui");String s2=req.getParameter("apw");String query1="select adminid from madmininfo";ResultSet rs1=st.executeQuery(query1);while(rs1.next()){ String cc1=rs1.getString(1); if(s1.trim().equalsIgnoreCase(cc1))

    {i=1; }

    } if(i==1)

    {pw.println("");pw.println("");pw.println("exist");pw.println(""); pw.println("");

    pw.println("");pw.println("");pw.println("");pw.println(""); pw.println("This User Name");pw.println(""+ s1 +"");

  • pw.println("is already registered");pw.println("");pw.println("Please change User Name");pw.println("");

    pw.println(""); pw.println("Back..");

    pw.println(""); pw.println(""); }else { int i1=st.executeUpdate("insert into madmininfo values('"+ s1 +"

    ','"+ s2 +"')"); pw.println(""); pw.println(""); pw.println("New Administration-ID is created Successfully"); pw.println("Back.."); pw.println("");st.close(); con.close();pw.close(); }}catch(Exception e) { e.printStackTrace(); pw.println(e.toString()); } } } 22.USERS CHANGE PASSWORDimport java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;import java.net.*;public class AUsersu extends HttpServlet { String s1,s2,s3; boolean flag=false; public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException { res.setContentType("text/html"); ServletOutputStream out=res.getOutputStream(); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:online"); Statement st=c.createStatement(); ResultSet rs=st.executeQuery("select adminid,adminpw from madmininfo"); s1=req.getParameter("aui"); s2=req.getParameter("aopw"); s3=req.getParameter("anpw"); String s4=""; String s5=""; while(rs.next()) { s4=rs.getString(1); s5=rs.getString(2); if(s4.equals(s1) && s5.equals(s2))

  • { int i=st.executeUpdate("update madmininfo set adminpw='"+s3+"' where adminid='"+s1+"'"); res.sendRedirect("http://localhost:8080/aus.html"); flag=true; } } if(flag=false) { out.println(""); //out.println(""); out.println(""); out.println("Sorry U are un authorised USER"); out.println(""); out.println(""); out.println(""); } rs.close(); st.close(); c.close(); } catch(Exception e) { out.println(e.toString()); } }}23 USERS DELETION(This progrm includes AAD javafile)import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.net.*;import java.sql.*;public class AAdel extends HttpServlet { public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); res.setContentType("text/html"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:online","scott","tiger"); Statement st=c.createStatement(); ResultSet rs=st.executeQuery("select * from madmininfo"); out.println(""); out.println(""); out.println("function f1()"); out.println("{"); out.println("window.location.href='http://localhost:8080/ausersd.html';"); out.println("}"); out.println(""); String code; out.println(""); out.println(""); out.println("");

  • out.println("Select Adminstrator Name "); while(rs.next()) { code=rs.getString(1); out.println("" + code); } out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); rs.close(); st.close(); c.close(); } catch(Exception e) { out.println(e.toString()); } } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { doGet(req,res); }}24.AAD PROGRAMimport java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.net.*;import java.sql.*;public class AAD extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); res.setContentType("text/html"); String code; code=req.getParameter("code"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:online"); Statement st=c.createStatement(); int i=st.executeUpdate("delete from madmininfo where adminid='"+ code +"'");

    out.println(""); out.println(""); out.println(""); out.println("Record " + code +" is Deleted Successfully"); out.println("Back.."); out.println(""); st.close(); c.close(); } catch(Exception e) { out.println(e.toString()); } }

  • public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { doGet(req,res); }}25 NEWUSERS CREATEDimport java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;public class NewUsers extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); res.setContentType("text/html"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:online"); Statement st=c.createStatement(); String user=req.getParameter("ui"); String passwd=req.getParameter("pw"); String fname=req.getParameter("fn"); String lname=req.getParameter("ln"); String day=req.getParameter("d"); String month=req.getParameter("m"); String year=req.getParameter("y"); String date=day + "/" + month + "/" + year; String gender=req.getParameter("g1"); String occupation=req.getParameter("o"); ResultSet rs=st.executeQuery("select loginid from musersinfo"); boolean exist=false; while(rs.next()) { if(rs.getString(1).equals(user)) exist=true; } out.println(""); if(exist==false) { int i=st.executeUpdate("insert into musersinfo values('" + user + "','" + passwd + "','" + fname + "','" + lname + "','" + date + "','" + gender + "','" + occupation + "')"); out.println(""); out.println(""); out.println("The User"); out.println("'"+user +"' is Created successfully"); out.println(""); out.println(""); } else { out.println("Sorry!. An User with " + user + " is already existing.Please Choose another login ID."); out.println("Back");

  • out.println(""); } out.println(""); st.close(); c.close(); } catch(Exception e) { out.println("");

    out.println("Please fill all fields in the entry form");

    out.println("Back"); out.println(""); } } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { doGet(req,res); }} 26.ALREADY CREATED USERSimport java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.sql.*;import java.net.*;public class RPWLogin extends HttpServlet{ public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out=res.getWriter(); res.setContentType("text/html"); boolean flag=false; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection("jdbc:odbc:online"); Statement st=c.createStatement(); ResultSet rs=st.executeQuery("select loginid,password from musersinfo"); String user=req.getParameter("ui"); String passwd=req.getParameter("pw"); String s3=""; String s4=""; while(rs.next()) { s3=rs.getString(1); s4=rs.getString(2); if(s3.equals(user) && s4.equals(passwd)) { res.sendRedirect("http://localhost:8080/instr.html"); flag=true; } } if(flag==false) { out.println(""); out.println(""); out.println(""); out.println("Sorry U are an un authorised USER

  • ORinvald Username and Password");out.println("Back");

    out.println(""); out.println(""); out.println(""); } rs.close(); st.close(); c.close(); } catch(Exception e) { out.println(e.toString()); } } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { doGet(req,res); }}