Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
80 views

MiniProject 1 AdvJava

This document outlines a Java web application project involving JSP, Servlets, and JDBC for user registration. It includes code snippets for the header JSP, registration and login JSP forms, a servlet class to handle form submission and database insertion, and a JDBC utility class to connect to MySQL and execute an INSERT statement. The servlet retrieves form data, makes a database call using the JDBC class, and forwards to the registration JSP with a success or failure message.

Uploaded by

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

MiniProject 1 AdvJava

This document outlines a Java web application project involving JSP, Servlets, and JDBC for user registration. It includes code snippets for the header JSP, registration and login JSP forms, a servlet class to handle form submission and database insertion, and a JDBC utility class to connect to MySQL and execute an INSERT statement. The servlet retrieves form data, makes a database call using the JDBC class, and forwards to the registration JSP with a success or failure message.

Uploaded by

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

- by RAGHU SIR [Sathya Technologies, Ameerpet]

JSP-Servlets-JDBC-Mini Project#1
1. Header.jsp

<img src="logo.jpg"/>
<marquee>Welcome to Sathyatech App</marquee>
<table>
<tr>
<td>
<a href="Login.jsp">Login</a>
</td>
<td>
<a href="Register.jsp">Register</a>
</td>

</tr>
</table>

2.Register.jsp

<%@ page language="java" contentType="text/html;


charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%@include file="Header.jsp" %>

<h3>Welcome to Register page</h3>

1|P ag e
- by RAGHU SIR [Sathya Technologies, Ameerpet]

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


<pre>
UserName : <input type="text" name="un"/>
Email : <input type="text" name="email"/>
Contact : <input type="text" name="contact"/>
Password : <input type="password" name="pwd"/>
Address : <textarea name="addr"></textarea>
<input type="submit" value="Register"/>
</pre>
</form>
<%
Object msg=request.getAttribute("msg");
if(msg!=null)
out.println(msg);
%>
</body>
</html>

3. Login.jsp

<%@ page language="java" contentType="text/html;


charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%@include file="Header.jsp" %>

<h3>Welcome to Login Page</h3>


<form action="#" method="post">
<pre>
2|P ag e
- by RAGHU SIR [Sathya Technologies, Ameerpet]

User : <input type="text" name="un"/>


Password : <input type="password" name="pwd"/>
<input type="submit" value="Login"/>
</pre>
</form>
</body>
</html>

4.Servlet class

package com.app.servlet;

import java.io.IOException;

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 com.app.jdbc.RegisterJdbc;

@WebServlet("/register")
public class RegisterServlet
extends HttpServlet
{

public void doPost(


HttpServletRequest req,
HttpServletResponse resp)
throws ServletException,
IOException {
//1. read form data
3|P ag e
- by RAGHU SIR [Sathya Technologies, Ameerpet]

String un=req.getParameter("un");
String email=req.getParameter("email");
String contact=req.getParameter("contact");
String pwd=req.getParameter("pwd");
String addr=req.getParameter("addr");

//make DB call
int count=RegisterJdbc.process(un, email, contact,
pwd, addr);
String message=null;
if(count==0) {
message="Fail!";
}else {
message="Success!!";

}
RequestDispatcher
rd=req.getRequestDispatcher("/Register.jsp");
req.setAttribute("msg",message);
rd.forward(req, resp);

5. JDBC code

package com.app.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class RegisterJdbc {

public static int process(


String un,
String email,
4|P ag e
- by RAGHU SIR [Sathya Technologies, Ameerpet]

String contact,
String pwd,
String addr)
{
String sql="insert into usrstab values(?,?,?,?,?)
";
int count=0;
try {
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306
/test", "root", "root");
PreparedStatement
pstmt=con.prepareStatement(sql);

pstmt.setString(1, un);
pstmt.setString(2, email);
pstmt.setString(3, contact);
pstmt.setString(4, pwd);
pstmt.setString(5, addr);

count=pstmt.executeUpdate();

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

return count;
}
}

DB Table:-
/*
CREATE TABLE usrstab (
un varchar(25) ,
email varchar(25) ,
contact varchar(20) ,
5|P ag e
- by RAGHU SIR [Sathya Technologies, Ameerpet]

pwd varchar(20) ,
addr varchar(50)
)

*/

FB:
https://www.facebook.com/groups/thejavatemple

6|P ag e

You might also like