You are on page 1of 14

8.

Design and development of Online Examination using JSP

Login.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"%>

<%@ page import="java.sql.*"%>

<!DOCTYPE html>

<html>

<head>

<title>Login Page</title>

</head>

<body>

<form action="LoginServlet" method="post">

Username: <input type="text" name="username" required><br>

Password: <input type="password" name="password" required><br>

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

</form>

</body>

</html>

LoginServelet.Java

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class LoginServlet extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,


IOException {

String username = request.getParameter("username");

String password = request.getParameter("password");

// Validate username and password (you should use secure authentication)

if (username.equals("admin") && password.equals("admin")) {

HttpSession session = request.getSession();


session.setAttribute("username", username);

response.sendRedirect("Welcome.jsp");

} else {

response.sendRedirect("Login.jsp");

Welcome.JSP

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"%>

<%@ page import="java.util.*"%>

<!DOCTYPE html>

<html>

<head>

<title>Welcome Page</title>

</head>

<body>

<h2>Welcome, <%= session.getAttribute("username") %></h2>

<a href="LogoutServlet">Logout</a>

</body>

</html>

LogoutServlet.java

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class LogoutServlet extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,


IOException {

HttpSession session = request.getSession();

session.invalidate();

response.sendRedirect("Login.jsp");
}

Online.html

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Online Exam</title>

</head>

<body>

<h1>Online Exam</h1>

<form action="submit_exam.php" method="post">

<h2>Question 1:</h2>

<p>What is the capital of France?</p>

<label><input type="radio" name="q1" value="paris"> Paris</label><br>

<label><input type="radio" name="q1" value="london"> London</label><br>

<label><input type="radio" name="q1" value="berlin"> Berlin</label><br>

<h2>Question 2:</h2>

<p>Which programming language is this example written in?</p>

<label><input type="radio" name="q2" value="html"> HTML</label><br>

<label><input type="radio" name="q2" value="java"> Java</label><br>

<label><input type="radio" name="q2" value="python"> Python</label><br>

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

</form>

</body>

</html>
9.Design and development of online job using jsp

SOURCE CODE:

Index.jsp

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body style="background-color:#EEEEEE; color:#0000FF;">
<div style="position:absolute;left:200px;top:100px;">

<form action="student1.jsp" method="POST">


<table id="tb" >
<tr>
<td>
<h3> Enter personal details </h3>
</td>
</tr>
<tr>
<td>Enter Name:</td><td><input type="text"
name="txtname"value=""/></td>
</tr>
<tr>
<td> Enter Password:</td> <td> <input type="password"
name="txtpwd"value="" /></td>
</tr>
<tr>
<td> Conform Password:</td> <td> <input type="password"
name="txtpwd1"value="" /></td>
</tr>
<tr>
<td>
Fathers Name
</td>
<td>
<input type="text" name="fname" value=""/>
</td>
</tr>
<tr>
<td>
Mothers Name
</td>
<td>
<input type="text" name="mname" value=""/>
</td> </tr>
/></td>
<tr>
<td>Enter Address:</td>
<td>
<textarea name="txtaddr" rows="4" cols="20" >
</textarea>
</td>
</tr>
<tr>
<td>SEX :</td>
<td>MALE<input type="radio" name="sex" value="male" checked="checked"

<td>FEMALE<input type="radio" name="sex" value="female" /></td>


</tr>

<tr>
<td>STATE:</td>
<td><select name="state">
<option>Kerala</option>
<option>Tamilnadu</option>
<option>Karnataka</option>
<option>Oria</option>
<option>Maharashtra</option>
</select>
</td>
</tr>

<tr>
<td>Branch</td>
<td>10th<input type="checkbox" name="ten" value="10th" /></td>
<td>Plus Two<input type="checkbox" name="ten" value="PlusTwo" /></td>
<td>Degree<input type="checkbox" name="ten" value="Degree" /></td>
</tr>

<tr>
<td>
AGE
</td>

<td>
<select name="age">
<%

for (int i = 18; i < 36; i++) {out.print("<option>" + i + "</option>");


}
%>
</select>
</td>
</tr>
<tr><td><input type="submit" value="submit" /></td></tr>
</table>
</form>

</div>
</body>
</html>

student1.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<div style="position:absolute;left:200px;top:50px;font-family:Tahoma;font-size:16px;">
<%
String name = request.getParameter("txtname");
String pwd = request.getParameter("txtpwd");
String pwd1 = request.getParameter("txtpwd1");
String adr = request.getParameter("txtaddr"); String
sx = request.getParameter("sex");
String state = request.getParameter("state"); String
ten[] = request.getParameterValues("ten");String
age = request.getParameter("age");
String fname = request.getParameter("fname");
String mname = request.getParameter("mname");
int i;
out.println("<b>");

if (pwd != "") {
if (pwd.equals(pwd1)) {
out.println("<table cellpadding=\"10\"
style=\"border:1px solidblack;padding:20px;
\">");
out.println("<tr><td>Name :</td><td>" + name + "</td></tr>");
out.println("<tr><td>Fathers Name :</td><td>" + fname +
"</td></tr>"); out.println("<tr><td>Mothers Name :</td><td>" +
mname + "</td></tr>"); out.println("<tr><td>Password :</td><td>"
+ pwd + "</td></tr>"); out.println("<tr><td>Address :</td><td>" +
adr + "</td></tr>"); out.println("<tr><td>Sex :</td><td>" + sx +
"</td></tr>"); out.println("<tr><td>State :</td><td>" + state +
"</td></tr>");
out.println("<tr><td><u>QUALIFICATION</u></td></tr>");

for (i = 0; i < ten.length; i++) {


out.println("<tr><td>" + ten[i] + "</td>" + "</tr>");
}

out.println("<tr><td>AGE:" + age + "</td></tr>");

out.println("</table>");
} else {
out.println("Pass Word Mismatch");
}
} else {
out.println("Pass Word Can not be null");
}
out.println("</b>");
%>

</div>
</body>
</html>
OUTPUT:
10.Design and development of online message System

input. SOURCE CODE:


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body style="background-color:#EEEEEE; color:#0000FF;">
<div style="position:absolute;left:200px;top:100px;">
<form action="message.jsp" method="POST">
<table id="tb" >
<tr>
<td>
<h3> Student Details </h3>
</td>
</tr>
<tr>
<td>Enter Name:</td><td><input type="text" name="txtname"value=""/></td>
</tr>
<tr>
<td>
course
</td>
<td><select name="course">
<option>B.Tech</option>
<option>MBA</option>
<option>MCA</option>
</select>
</td>
</tr>
<tr>
<td>
Place of Stay
</td>
<td>
Hostel<input type="radio" name="place"
value="hostel" />DayScholar<input
type="radio" name="place" value="day" />
</td>
</tr>
<tr>

<td>Enter Percentage of Mark:</td><td><input type="text" name="per"


value=""/></td>
</tr>
<tr>
<td>
<input type="submit" value="submit" />
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
message.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<div style="position:absolute;left:200px;top:50px;font-family:Tahoma;font-size:16px;">
<%
String name = "", course = "", place = "", per = ""; if
(request.getParameter("txtname") != null) {
name = request.getParameter("txtname");
}
if (request.getParameter("course")
!= null) {course =
request.getParameter("course");
}
if (request.getParameter("place") != null) {place = request.getParameter("place");
}
if (request.getParameter("per")
!= null) {per =
request.getParameter("per");
}
%>
You are Mr./Ms <% out.println(name);%> studying in the <%
out.println(course);%>course and<br>
your place of stay is <% out.println(place);%>. You had <% out.println(per); %>%
ofmarks in<br>the qualifying examination.
</div>
</body>
</html>

You might also like