Exp8 M2
Exp8 M2
Exp8 M2
AIM:
To implement a web application based on the MVC design pattern with data base.
ALGORITHM
Step 1 : create a database named "employee" in MySQL. Let's create an employee1 table using below DDL script:
CREATETABLEemployee1
(idint,first_namevarchar(20),last_namevarchar(20),usernamevarchar(250),passwordvarchar(20) ,addressvarchar(45
),contactvarchar(45));
Step 2: Create the Employee class which will act as our Model class.
Step 3: EmployeeDao class that contains JDBC code to connect with the MySQL database.
Step 4: create an EmployeeServlet class to process HTTP request parameters and redirect to the
appropriate JSP page after request data stored in the database:
Step 6:After an employee successfully registered then employeedetails.jsp show a successful message on screen
PROGRAM:
Employee.java
package com.pu;
import java.io.*;
publicclass Employee {
privateintid;
private String firstName;
private String lastName;
private String username;
private String password;
private String address;
private String contact;
EmployeeServlet.java
package com.pu;
import java.sql.*;
import jakarta.servlet.*;
import java.io.*;
} catch (Exception e) {
System.err.println(e);
}
}
employeeregister.jsp
<%@pagelanguage="java"contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPEhtml>
<html>
<head>
<metacharset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Employee Register Form</h1>
<formaction="EmployeeServlet"method="post">
<tablestyle="with: 50%">
<tr>
<td>Registration Id</td>
<td><inputtype="text"name="id"/></td>
</tr>
<tr>
<td>First Name</td>
<td><inputtype="text"name="firstName"/></td>
</tr>
<tr>
<td>Last Name</td>
<td><inputtype="text"name="lastName"/></td>
</tr>
<tr>
<td>UserName</td>
<td><inputtype="text"name="username"/></td>
</tr>
<tr>
<td>Password</td>
<td><inputtype="password"name="password"/></td>
</tr>
<tr>
<td>Address</td>
<td><inputtype="text"name="address"/></td>
</tr>
<tr>
<td>Contact No</td>
<td><inputtype="text"name="contact"/></td>
</tr>
</table>
<inputtype="submit"value="Submit"/></form>
</body>
</html>
employeedetail.jsp
<%@pagelanguage="java"contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@pageimport="com.pu.*"%>
<!DOCTYPEhtml>
<html>
<head>
<metacharset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
out.print("You are successfully registered");
%>
</body>
</html>
RESULT:
Thus, to implement a simple MVC web application using JSP and Servlet.