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

New WT

Uploaded by

Neha Verma
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)
11 views

New WT

Uploaded by

Neha Verma
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/ 38

KRISHNA ENGINEERING COLLEGE

(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

Session 2022-23 EVEN Semester


Practical no………….1……………..Name of the Practical………………………………….…………
Student Roll no………………….…Name of Student…………………..Branch/Semester………

AIM: Write HTML/CSS code to display your Resume.

CODE:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Assignment 1</title>
<style>
body{
background-color: pink;
}
</style>
</head>
<body>
<h3 align="center">
RESUME
</h3>
<h5>Name : Neha Verma</h5>
<h5>Course : B.Tech(CSE)</h5>
<h5>Mob No. : 8800552836</h5>
<h5>E-Mail : <a
href="mailto:[email protected]">nehaverma30092002
@gmail.com</a></h5>
<hr>
<h5>Career Objective:</h5>
<p>To seek a challenging position that allows me to utilize my
education and technical experience while gaining

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

valuable work experience in a team oriented environment , to


help me as a fresher to grow.</p>
<h5>Educational Qualification:</h5>
<table border="1">
<tr>
<th>&nbsp;&nbsp;</th>
<th>Passing Year</th>
<th>School Name</th>
<th>CGPA/Percentage</th>
</tr>
<tr>
<th>10<sup>th</sup></th>
<td align="center">2018</td>
<td align="center">Spring Meadows Public School</td>
<td align="center">87.8%</td>
</tr>
<tr>
<th>12<sup>th</sup></th>
<td align="center">2020</td>
<td align="center">Spring Meadows Public School</td>
<td align="center">85.8%</td>
</tr>
<tr>
<th>B.Tech</th>
<td align="center">2024</td>
<td align="center">Krishna Engineering College</td>
<td align="center">---</td>
</tr>

</table>
<h5>C0-Curricular / Extra Activities:</h5>
<ol>
<li>
Attended " Abhyuday Ka Amrit Mahotsav " as a participant
organized by ITS College(Gzb),
Chief Guest : Shri Lakko Venkateshwarlu (IAS).
</li>

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

<li>
Participated in Coding Contest of C , C++.
</li>
<li>
Participation in TechGuru as a Team Member.
</li>
<li>
Attended "National Service Scheme" Organised by Krishna
Engineering College(Gzb),
Chief Guest: prof.(Dr.) Shailesh Tiwari.
</li>
</ol>
<h5>Achievements:</h5>
<ol type="i">
<li>
Certified in Machine Learning with Python by IBM.
<a href="https://courses.skillsbuild.skillsnetwork.site/certificates/
d04ef4 3820e146a4a75723f509726a8c">certificate</a>

</li>
<li>
Certified in Data Analysis with Python by IBM.
</li>

</ol>
<h5>Projects :</h5>
<ol>
<li>
Mini Project using C.<br>
Duration :: 84 hours.<br>
Description :: In this project, Snake Water Gun Game was
designed using C which hepls to enhance
the basic knowledge of c, so that it builds the base of any
language. It increases the logic making process.
</li>
<li>

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

Portfolio Website.<br>
Duration :: 2 Months.<br>
Description :: It consists of skills , qualifications, education ,
training and experiences as a freshers.
</li>
</ol>
<br>
<h5>Date : 21<sup>th</sup>May 2023</h5>
</body>
</html>

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

OUTPUT::

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

Session 2022-23 EVEN Semester


Practical no……………2……………..Name of the Practical………………………………….…………
Student Roll no………………….…Name of Student…………………..Branch/Semester………

AIM: Write HTML/CSS to display registration page.

CODE:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Form</title>

<style>

.required:after {
content:" *";
color: black;
}
body{
background-color: darksalmon;
}

</style>
</head>
<body >
<h1>Registration Form</h1>

<table >
<tr><td><label class="required">User Name
</label></td><td><input type="text" ></input></td></tr>

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

<tr><td><label class="required">Password
</label></td><td><input type="password" ></input></td></tr>
<tr><td><label class="required">E-Mail </label></td><td><input
type="email"></input></td></tr>
<tr><td><label class="required">Mobile No
</label></td><td><input type="number" ></input></td></tr>
<tr><td><label class="required">Course </label></td><td><input
type="radio" name="rd">B.Tech</input><input type="radio"
name="rd">MBA</input></td></tr>
<tr><td>&nbsp;&nbsp;</td><td><input type="submit"
></input></td</tr>

</table>
<hr height="5px">
<span >* <b><i>fields are mandatory</i></b></span>
</body>
</html>

OUTPUT:

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

Session 2022-23 EVEN Semester


Practical no…………3………………..Name of the Practical………………………………….…………
Student Roll no………………….…Name of Student…………………..Branch/Semester………

AIM: Write HTML/Javascript to display Registration Page.

CODE:

<!DOCTYPE html>
<html>
<head>
<title>Registration Page</title>
<script>
function validateForm() {
var firstName = document.getElementById("firstName").value;
var lastName = document.getElementById("lastName").value;
var email = document.getElementById("email").value;
var password = document.getElementById("password").value;

if (firstName === "" || lastName === "" || email === "" || password
=== "") {
alert("All fields are required!");
return false;
}
return true;
}
</script>
</head>
<body>
<h2>Registration Page</h2>
<form onsubmit="return validateForm()">
<label for="firstName">First Name:</label>
<input type="text" id="firstName" name="firstName" required><br>

<label for="lastName">Last Name:</label>


<input type="text" id="lastName" name="lastName" required><br>

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br>

<label for="password">Password:</label>
<input type="password" id="password" name="password"
required><br>

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


</form>
</body>
</html>

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

OUTPUT::

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

Session 2022-23 EVEN Semester


Practical no……………4……………..Name of the Practical………………………………….…………
Student Roll no………………….…Name of Student…………………..Branch/Semester………

AIM: Write a Java applet to display the Application Program screen i.e. calculator
and other.
Code:

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Cal extends Applet
implements ActionListener
{
String msg=" ";
int v1,v2,result;
TextField t1;
Button b[]=new Button[10];
Button add,sub,mul,div,clear,mod,EQ;
char OP;
public void init()
{
Color k=new Color(120,89,90);
setBackground(k);
t1=new TextField(10);
GridLayout gl=new GridLayout(4,5);
setLayout(gl);
for(int i=0;i<10;i++)
{

b[i]=new Button(""+i);
}
add=new Button("add");
sub=new Button("sub");
mul=new Button("mul");
div=new Button("div");
mod=new Button("mod");
clear=new Button("clear");
EQ=new Button("EQ");
t1.addActionListener(this);
add(t1);

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

for(int i=0;i<10;i++)
{
add(b[i]);
}
add(add);
add(sub);
add(mul);
add(div);
add(mod);
add(clear);
add(EQ);
for(int i=0;i<10;i++)
{
b[i].addActionListener(this);
}
add.addActionListener(this);
sub.addActionListener(this);
mul.addActionListener(this);

div.addActionListener(this);
mod.addActionListener(this);
clear.addActionListener(this);
EQ.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
char ch=str.charAt(0);
if ( Character.isDigit(ch))
t1.setText(t1.getText()+str);
else
if(str.equals("add"))
{
v1=Integer.parseInt(t1.getText());
OP='+';
t1.setText("");
}
else if(str.equals("sub"))
{
v1=Integer.parseInt(t1.getText());
OP='-';
t1.setText("");
}

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

else if(str.equals("mul"))
{
v1=Integer.parseInt(t1.getText());
OP='*';

t1.setText("");
}
else if(str.equals("div"))
{
v1=Integer.parseInt(t1.getText());
OP='/';
t1.setText("");
}
else if(str.equals("mod"))
{
v1=Integer.parseInt(t1.getText());
OP='%';
t1.setText("");
}
if(str.equals("EQ"))
{
v2=Integer.parseInt(t1.getText());
if(OP=='+')
result=v1+v2;
else if(OP=='-')
result=v1-v2;
else if(OP=='*')
result=v1*v2;
else if(OP=='/')
result=v1/v2;
else if(OP=='%')
result=v1%v2;
t1.setText(""+result);
}

if(str.equals("clear"))
{
t1.setText("");
}
}
}

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

OUTPUT:

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering


Session 2022-23 EVEN Semester

Practical no…………5………………..Name of the Practical………………………………….…………


Student Roll no………………….…Name of Student…………………..Branch/Semester………

AIM: Writing program in XML for creation of DTD, which specifies set of rules.
Create a stylesheet in CSS/ XSL & display the document in internet explorer.

CODE:

XML code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="neha.xsl"?>

<!DOCTYPE book [
<!ELEMENT book (title, author, publisher, year, price)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT price (#PCDATA)>
<!ATTLIST book id CDATA #IMPLIED>
]>
<book id="bk2001">
<title>Harry Potter</title>
<author>J.K. Rowling</author>
<publisher>Bloomsbury Publishing</publisher>
<year>1997</year>
<price>5114</price>
</book>

XSL Code:

<?xml version="1.0" encoding="UTF-8"?>


<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>

<head>
<title>Book Details</title>
<link rel="stylesheet" type="text/css" href="book.css"/>
</head>

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

<body>
<h1>Book Details</h1>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="book">
<div>
<xsl:apply-templates select="title"/>
<xsl:apply-templates select="author"/>
<xsl:apply-templates select="publisher"/>
<xsl:apply-templates select="year"/>
<xsl:apply-templates select="price"/>
</div>
</xsl:template>
<xsl:template match="title">
<h2>
<xsl:value-of select="."/>
</h2>
</xsl:template>
<xsl:template match="author">
<p>

By <xsl:value-of select="."/>
</p>
</xsl:template>
<xsl:template match="publisher">
<p>
Published by <xsl:value-of select="."/>
</p>
</xsl:template>
<xsl:template match="year">
<p>
Published in <xsl:value-of select="."/>
</p>
</xsl:template>
<xsl:template match="price">
<p>
Price: Rs<xsl:value-of select="."/>
</p>
</xsl:template>
</xsl:stylesheet>

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

OUTPUT:

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

Session 2022-23 EVEN Semester


Practical no……………6……………..Name of the Practical………………………………….…………
Student Roll no………………….…Name of Student…………………..Branch/Semester………

AIM: Create a registration page which takes data and store it into database using HTML
and Servlet.

CODE:

DATABASE:

CREATE TABLE LOGIN


(
Name VARCHAR2(100),
Email VARCHAR2(100),
Password VARCHAR2(100)
)

Html Code:

<html>
<body>
<form action="RegisterServlet" method="post"> Name:
<input type="text" name="name" />
<br />
<br /> Email Id:
<input type="text" name="email" />
<br />
<br /> Password:
<input type="password" name="password" />
<br />
<br />
<br />
<br />
<input type="submit" value="register" formaction="RegisterServlet">
<input type="submit" value="Login" formaction="LoginServlet"> </form>
</body>
</html>

Servlet code:

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

package com.servlet;
import java.io.*;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;

@WebServlet ("/RegisterServlet")
public class RegisterServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
public void doPost (HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
response.setContentType ("text/html");
PrintWriter out = response.getWriter ();

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


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

HttpSession session = request.getSession ();


session.setAttribute ("email", email);

try
{
Class.forName ("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection
("jdbc:mysql://localhost:3306/userdb", "root", "876745");
PreparedStatement ps = con.prepareStatement ("insert into
login values(?,?,?)");
ps.setString (1, name);
ps.setString (2, email);
ps.setString (3, password);

int i = ps.executeUpdate
(); if (i > 0)
out.print ("You are successfully registered...");
request.getRequestDispatcher ("Welcome1").include (request, response);

}
catch (Exception e2)
{

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

System.out.println (e2);
}
out.close ();
}
}

Java Code:

package com.servlet;
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 java.io.*;

@WebServlet("/Welcome1")
public class Welcome1 extends HttpServlet
{
private static final long serialVersionUID = 1L;
protected void doPost (HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
response.setContentType ("text/html");
PrintWriter out = response.getWriter ();
String user = request.getParameter
("name"); out.println ("</br></br>");
out.println ("Welcome " +
user); out.println
("</br></br>");
out.println ("<a >Click here to Login</a>");
}
}

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering


OUTPUT:

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

Session 2022-23 EVEN Semester

Practical no…………7………………..Name of the Practical………………………………….…………


Student Roll no………………….…Name of Student…………………..Branch/Semester………

AIM: Create a registration page which takes data and store it into database using HTML
and JSP page.

CODE:

HTML code:

<!DOCTYPE html>
<html>
<head>
<title>Registration Page</title>
</head>
<body>
<h2>Registration Page</h2>
<form action="registration.jsp" method="POST">
<label for="firstName">First Name:</label>
<input type="text" id="firstName" name="firstName" required><br>

<label for="lastName">Last Name:</label>


<input type="text" id="lastName" name="lastName" required><br>

<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br>

<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br>

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


</form>
</body>
</html>

JSP code:

<%@ page language="java" contentType="text/html; charset=UTF-8"


pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

<title>Registration Result</title>
</head>
<body>
<%-- Retrieve form data --%>
<% String firstName = request.getParameter("firstName"); %>
<% String lastName = request.getParameter("lastName"); %>
<% String email = request.getParameter("email"); %>
<% String password = request.getParameter("password"); %>

<%-- Perform registration logic here (e.g., store the user in a database) --%>

<h2>Registration Successful</h2>
<p>Thank you, <%= firstName %>, for registering!</p>
</body>
</html>

OUTPUT:

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

Session 2022-23 EVEN Semester


Practical no…………8………………..Name of the Practical………………………………….…………
Student Roll no………………….…Name of Student…………………..Branch/Semester………

AIM: Create a Message page using JavaBeans in JSP page.

CODE:

Java Code:

package Action;
public class Test {
private String message = "No message specified";
public String getMessage() {
return (message);
}

public void setMessage(String message) {


this.message = message;
}
}

JSP page:

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


pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Using JavaBeans in JSP</title>
</head>

<body>
<h2>Using JavaBeans in JSP</h2>
<jsp:useBean id="test" class="Action.Test" />
<jsp:setProperty name="test" property="message" value="Hello JSP. ." />

<p>Got message. . .</p>


<jsp:getProperty name="test" property="message" />
</body>
</html>

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

OUTPUT:

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

Session 2022-23 EVEN Semester


Practical no…………9………………..Name of the Practical………………………………….…………
Student Roll no………………….…Name of Student…………………..Branch/Semester………

AIM: Write a Java program/Servlet/JSP to Insert the Details of user who register with the
Website and connect to the database and extract data from the table and authenticate them by
displaying their name.

CODE:

Index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="login.jsp" method="post">
User name :<input type="text" name="usr" /><br><br> password :<input
type="password" name="password" /><br> <br><input type="submit"
/>
</form>
<p>
New user. <a href="hello.html">Login Here</a>
</body>
</html>

Login.jsp

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


pageEncoding="ISO-8859-1"%>
<%@page import="java.sql.*,java.util.*"%>
<%
String userid = request.getParameter("userid");
session.putValue("userid", userid);
String password = request.getParameter("password");
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/students", "root",
"root");
Statement st = con.createStatement();

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

ResultSet rs = st.executeQuery("select * from users where userid='" + userid + "'


and password='" + password + "'");
try {
rs.next();
if (rs.getString("password").equals(password) &&
rs.getString("userid").equals(userid)) {
out.println("<h2>Welcome " + fname "</h2>");
} else {
out.println("Invalid password or username.");
}
} catch (Exception e) {
e.printStackTrace();
}
%>

hello.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="registrationProcess.jsp" method="post">
First name :<input type="text" name="fname" /> <br><br>Last name
:<input type="text" name="lname" /> <br><br>Email ID :<input type="text"
name="email" /><br><br> User name :<input type="text" name="userid"
/><br><br>
password :<input type="password" name="password" />
<br><br><input type="submit" />
</form>
</body>
</html>

registrationProcess.jsp

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


pageEncoding="ISO-8859-1"%>
<%@page import="java.sql.*,java.util.*"%>
<%
String fname = request.getParameter("fname");
String lname = request.getParameter("lname");

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

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


String userid = request.getParameter("userid");
String password = request.getParameter("password");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/students", "root",
"root");
Statement st = conn.createStatement();
int i = st.executeUpdate("insert into
users(fname,lname,email,userid,password)values('" + fname + "','" + lname
+ "','" + email + "','" + userid + "','" + password + "')");
out.println("Thank you for register ! Please <a href='index.html'>Login</a> to
continue.");
} catch (Exception e) {
System.out.print(e);
e.printStackTrace();
}
%>

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

OUTPUT:

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

Session 2022-23 EVEN Semester


Practical no…………10……………..Name of the Practical………………………………….…………
Student Roll no………………….…Name of Student…………………..Branch/Semester………

AIM: Create a Login Servlet using HTML and Servlet.

CODE:

Database Creation:

CREATE TABLE LOGIN


(
Name VARCHAR2(50),
Email VARCHAR2(100),
Password VARCHAR2(45)
)
Insert into LOGIN values(‘Neha’,’[email protected]’,’12345’);

Login.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Login Page</title>
</head>
<body>
<form action="LoginServlet" method="post">
Email ID:<input type="text" name="email" /><br />
<br /> Password:<input type="password" name="password" /><br />
<br /> <input type="submit" value="login" formaction="LoginServlet">
</form>
</body>
</html>

LoginServlet.java

package com.servlet;
import java.io.IOException;
import java.io.*;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import javax.servlet.http.HttpSession;

public class LoginServlet extends HttpServlet {


private static final long serialVersionUID = 1L;

protected void doPost(HttpServletRequest request,


HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
String email = request.getParameter("email");

session.setAttribute("email", email);
String password = request.getParameter("password");

try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/loginDB", "root",
"root");
PreparedStatement pst = conn
.prepareStatement("Select email,password from login where email=? and
password=?");
pst.setString(1, email);
pst.setString(2, password);
ResultSet rs = pst.executeQuery();
if (rs.next()) {
out.print("You are successfully loggedin...");
request.getRequestDispatcher("Welcome").include(request, response);
} else {

out.println("Username or Password incorrect");


request.getRequestDispatcher("Login.html").include(request, response);

}
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

}
}
}

Welcome.java

package com.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Welcome extends HttpServlet {


private static final long serialVersionUID = 1L;

protected void doPost(HttpServletRequest request, HttpServletResponse


response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("<form action='LoginServlet' method='post'>");
out.println("</br>Welcome user");
out.println("<input type='submit' value='logout' formaction='Login.html'>");
out.println("</form>");
}
}

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

OUTPUT::

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

INDEX
Student Roll no..…………………………………..Student name……………………………………..
Subject name…………………………………Subject code………………………………………………

Sno Practical name Scheduled Implementation Output Viva Total Signature

date (10 marks) (5 marks) (5 marks) (20 marks)

10

Faculty Incharge :
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

Subject Name:-………………………………………………………

Subject Code:- ………………………………………………………

Student Name:- ……………………………………………………

Roll no:- ………………………………………………………………..

Semester :- …………………………………………………………..

Branch & section :- ………………………………………………

Mohan Nagar, Near Air Force Station- Hindon, Ghaziabad – 201007


(U.P.)Tel: 0120-2657731, 2657732, TeleFax : 0120-2659513
Email: [email protected], Website : www.krishnacollege.ac.in

Faculty Incharge :

You might also like