0% found this document useful (0 votes)
12 views

Table

This document describes a registration and login system for a website called Sookshmas. It includes: 1) A database table called sookshmas1 to store user details with fields like name, phone, email and password. 2) A Registration.jsp page with a form to collect user details for registration. 3) A Servlet called register that handles form submission and inserts details into the database or checks for existing users. 4) A login.jsp page to display login status messages. 5) A Registration model class to connect to the database and check for existing users during registration.

Uploaded by

srushti hulyalad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Table

This document describes a registration and login system for a website called Sookshmas. It includes: 1) A database table called sookshmas1 to store user details with fields like name, phone, email and password. 2) A Registration.jsp page with a form to collect user details for registration. 3) A Servlet called register that handles form submission and inserts details into the database or checks for existing users. 4) A login.jsp page to display login status messages. 5) A Registration model class to connect to the database and check for existing users during registration.

Uploaded by

srushti hulyalad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Table:

CREATE TABLE sookshmas1 (


slno int(10) NOT NULL AUTO_INCREMENT,
name varchar(45) NOT NULL,
phone varchar(45) UNIQUE NOT NULL,
email varchar(45) UNIQUE NOT NULL,
password varchar(45) NOT NULL,
date datetime NOT NULL,
PRIMARY KEY (slno)
)

VIEW:
Registration.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<style>
input{
display: block;
}
#msg
{
background: red;
color:black;
border: 1px solid red;
width:24%;
font-weight: bold;
font-size: 25px;
padding: 5px;
}
</style>
<center>
<br><br>

<% if (request.getAttribute("status") != null) {%>


<div id="msg"> <%= request.getAttribute("status")%></div>
<%}%>
<form method="POST" id ="signup" action="register">
<font color="green">
<h2> Sookshmas Registration Form</h2>
</font>
<table>
<tr>
<td> NAME </td>
<td> <input type="text" id="name" name="name"</td>
</tr>
<tr>
<td> PHONE NUMBER </td>
<td> <input type="number" name="phone" > </td>
</tr>
<tr>
<td> Email </td>
<td> <input type="email" name="email"></td>
</tr>
<tr>
<td> Password </td>
<td> <input type="password" id="pw" name="pw"></td>
</tr>
<tr>
<td> Confirm Password </td>
<td> <input type="password" name="cp"></td>
</tr>
<tr>
<td> </br> <input type="submit" name="register"
value="Register"</td>
</tr>
</table>
</form>
</center>
</body>
</html>
Login.jsp:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>JSP Page</title>
</head>

<style>

#msg
{
background: green;
color:black;
border: 1px solid red;
width:24%;
font-weight: bold;
font-size: 25px;
padding: 5px;
}
</style>
<body>
<center>
<br><br>

<% if (request.getAttribute("status") != null) {%>


<div id="msg"> <%= request.getAttribute("status")%></div>
<%}%>
</center>

</body>
</html>

Servlet:

Under Controller package:


register.java: Servlet

package controller;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import model.Registration;

@WebServlet(urlPatterns = {"/register"})
public class register extends HttpServlet {
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
HttpSession session = request.getSession();

Registration reg = new Registration(session);


try
{
if (request.getParameter("register") != null) {

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


String phone = request.getParameter("phone");
String email = request.getParameter("email");
String pw = request.getParameter("pw");
String cp = request.getParameter("cp");

if (pw.equals(cp)) {
String status = reg.Registration(name, phone, email, pw);

if (status.equals("existed")) {
request.setAttribute("status", "Existed record");
RequestDispatcher rd1 =
request.getRequestDispatcher("Registration.jsp");
rd1.forward(request, response);

} else if (status.equals("success")) {
request.setAttribute("status", "Successfully Registered");
RequestDispatcher rd1 =
request.getRequestDispatcher("login.jsp");
rd1.forward(request, response);

} else if (status.equals("failure")) {
request.setAttribute("status", "Registration failed");
RequestDispatcher rd1 =
request.getRequestDispatcher("Registration.jsp");
rd1.forward(request, response);

}
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}

@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

@Override
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>

Model:
Registration.java

package model;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.http.HttpSession;

public class Registration

private Connection con;


HttpSession se;

public Registration(HttpSession session) {


try {

Class.forName("com.mysql.jdbc.Driver"); // load the drivers


con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/sookshma
s", "root", "root");
// connection with data base
se = session;
} catch (Exception e) {
e.printStackTrace();
}
}

public String Registration(String name, String phone, String email,


String pw) {
PreparedStatement ps;
String status = "";
try {
Statement st = null;
ResultSet rs = null;
st = con.createStatement();
rs = st.executeQuery("select * from sookshmas1 where phone='"
+ phone + "' or email='" + email + "';");
boolean b = rs.next();
if (b) {
status = "existed";
} else {
ps = con.prepareStatement("insert into sookshmas1
values(0,?,?,?,?,now())");
ps.setString(1, name);
ps.setString(2, phone);
ps.setString(3, email);
ps.setString(4, pw);
int a = ps.executeUpdate();
if (a > 0) {
status = "success";
} else {
status = "failure";
}
}

} catch (Exception e) {
e.printStackTrace();
}
return status;
}
}

You might also like