0% found this document useful (0 votes)
23 views3 pages

Ajava Exp10

Java program

Uploaded by

ppkkddpp179
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Ajava Exp10

Java program

Uploaded by

ppkkddpp179
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

EXPERIMENT 10

CODE:
Index.html
<html>
<body>
<h1>Quiz</h1>
<form method="get" action="QuizServ">
<label>What does not prevent JVM from terminating?</label><br />
<input type="radio" name="ql" value="a">Daemon Thread <br />
<input type="radio" name="ql" value="b">Process<br />
<input type="radio" name="gl" value="c">User Thread<br />
<input type="radio" name="ql" value="d">JVM Thread<br />
<br /><br />
<label>What decides thread priority?</label><br />
<input type="radio" name="q2" value="a">Process<br />
<input type="radio" name="d2" value="b">Thread scheduler<br />
<input type="radio" name="q2" value="">Thread<br />
<input type="radio" name="q2" value="d">Process scheduler <br /> <br /><br />
<label>Which of the following will ensure the thread will be in running state?</label><br />
<input type="radio" name="q3" value="a">yield()<br /> <input type="radio" name="q3" value="b">
notify()<br />
<input type="radio" name="q3" value="c">wait()<br />
<input type="radio" name="q3" value="d">Thread.killThread() <br />
<br /><br/>

<input type="submit" value="Submit">


<input type="reset" value="Reset">
</form>
</body>
</html>

QuizServlet.java
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import java.util.*;

public class QuizServ extends HttpServlet


{
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletExceptio
IOException {
PrintWriter out response.getWriter();
String paramName, paramValue();
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
int cnt=0;
String ans="";

Enumeration paramNames request.getParameterNames();


Enumeration paramNames-request.getParameterNames();
try
{
Class.forName("com.mysql.jdbc.Driver");
con-DriverManager.getConnection("jdbc:mysql://localhost/quapp", "root", "mysql"); stmt-
con.createStatement();
rs stmt.executeQuery("select ans from info");
while (rs.next() && paramNames.hasMoreElements())
{
String un=rs.getString(1);
paramName(String)paramNames.nextElement();
paramValue-request.getParameterValues (paramName);
for(int i=0;i<paramValue.length;i++)
{
ans-paramValue[i];
}
if(un.equals(ans))
cnt++;
}
out.println(" <h1>You have scored "+cnt+" points out of 3.</h1> ");
}
catch (Exception e)
{
out.println("Sorry!!! Try Again!!!");
}
}
}

quizResult.jsp
<!DOCTYPE html>
<html>
<head>
<title>Quiz Result</title>
</head>
<body>
<h1>You have scored "+cnt+" points out of 3.</h1>
</body>
</html>

OUTPUT:

You might also like