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

Web Technology

Html ,css and Java script are used in thos

Uploaded by

aryamayank4718
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)
13 views

Web Technology

Html ,css and Java script are used in thos

Uploaded by

aryamayank4718
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/ 44

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:-To Display Your CV In Navigator


Student Roll no:- Student Name:- Semester/Batch:-6

Aim: HTML/Java Scripts Code To Display Your CV In Navigator, Your Institute Website,
Department Details.
Code:
<!DOCTYPE html>
<html>
<head>
<title>My CV</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}

header {
background-color: #333;
color: #fff;
padding: 20px;
}

h1, h2, h3 {
margin-top: 0;
}

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
h1 {
font-size: 36px;
}

h2 {
font-size: 24px;
}

h3 {
font-size: 20px;
}

ul {
list-style: none;
margin: 0;
padding: 0;
}

section {
margin: 20px;
}

section h2 {
font-size: 24px;
margin-bottom: 10px;
}

section p {
line-height: 1.5;

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
margin: 0;
}

section ul li {
margin-bottom: 10px;
}

a{
color: #333;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<header>
<h1>Mr. XYZ</h1>
<p>Web Developer</p>
</header>

<section>
<h2>Summary</h2>
<p>A web developer with experience in HTML, CSS, and JavaScript.</p>
</section>

<section>

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
<h2>Experience</h2>
<h3>Web Developer, Anywhere Markets</h3>
<p>Jan 2023 - present</p>
<ul>
<li>Developed and maintained several company websites using HTML, CSS, and
JavaScript.</li>
<li>Collaborated with designers to implement new website features.</li>
<li>Optimized website performance through code improvements and server-side
caching.</li>
</ul>
</section>

<section>
<h2>Skills</h2>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>jQuery</li>
<li>WordPress</li>
<li>Drupal</li>
</ul>
</section>

<section>
<h2>About the Department</h2>
<p>The Department of Computer Science at the Krishna Engineering College offers
undergraduate and graduate programs in computer science.</p>
</section>

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering

<section>
<h2>Faculty</h2>
<ul>
<li>Mr. Kavindra Garg</li>
<li>Mr. Prashant Naresh</li>
<li>Mr. Rahul Rastogi</li>
<li>Mr. Deepak Sethi</li>
</ul>
</section>

<section>
<h2>Courses</h2>
<ul>
<li>Introduction to Computer Science</li>
<li>Data Structures and Algorithms</li>
<li>Operating Systems</li>
<li>Database Systems</li>
<li>Software Engineering</li>
</ul>
</section>

<section>
<h2>Research Areas</h2>
<ul>
<li>Artificial Intelligence</li>
<li>Computer Networks</li>
<li>Distributed Systems</li>
<li>Human-Computer Interaction</li>

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
<li>Software Engineering</li>
</ul>
</section>

<section>
<h2>Contact Information</h2>
<p>Department of Computer Science<br>
Krishna Engineering College<br>
Mohan Nagar,GZB<br>
India<br>
Phone: 9999110872<br>
<a href="https://www.krishnacollege.ac.in/">College Details</a>

</section>
</body>
</html>

Faculty Remarks & Signature


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 Remarks & Signature


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:-To Design An Entry Form Of Student Details
Student Roll no:- Student Name:- Semester/Batch:-6

Aim: Html Program To Design An Entry Form Of Student Details And Send It store At
Database Server Like SQL, Oracle Or MS Access.
Code:
<!DOCTYPE html>
<html>
<head>
<title>Student Entry Form</title>
</head>
<body>
<h1>Student Entry Form</h1>
<form action="submit.php" method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br>

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

<label for="phone">Phone:</label>
<input type="tel" id="phone" name="phone" required><br>

<label for="dob">Date of Birth:</label>


<input type="date" id="dob" name="dob" required><br>

<label for="gender">Gender:</label>

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
<input type="radio" id="male" name="gender" value="male" required>
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="female" required>
<label for="female">Female</label><br>

<label for="address">Address:</label>
<textarea id="address" name="address" required></textarea><br>

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


</form>
</body>
</html>
Database Connection: Using Php
<?php
// Connect to database
$servername = "localhost";
$username = "yourusername";
$password = "yourpassword";
$dbname = "yourdatabase";

$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

// Get form data


$name = mysqli_real_escape_string($conn, $_POST['name']);

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
$email = mysqli_real_escape_string($conn, $_POST['email']);
$phone = mysqli_real_escape_string($conn, $_POST['phone']);
$dob = mysqli_real_escape_string($conn, $_POST['dob']);
$gender = mysqli_real_escape_string($conn, $_POST['gender']);
$address = mysqli_real_escape_string($conn, $_POST['address']);

// Insert data into database


$sql = "INSERT INTO students (name, email, phone, dob, gender, address)
VALUES ('$name', '$email', '$phone', '$dob', '$gender', '$address')";

if (mysqli_query($conn, $sql)) {
echo "Record added successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);
?>

Faculty Remarks & Signature


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 Remarks & Signature


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:-To Display Browsers Information


Student Roll no:- Student Name:- Semester/Batch:-6

Aim: Programs Using Java Script For Web Page To Display To Browsers Information.
Code:
<html>
<body>
<script type="text/javascript">
document.write("Browser Name: "+ navigator.appName);
document.write("Browser Version: "+ navigator.appVersion);
document.write("Cookies Enabled: "+ navigator.cookieEnabled);
document.write("Platform: "+navigator.platform);
document.write("User-agent header: " +navigator.userAgent);
</script></body>
</html>

Faculty Remarks & Signature


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 Remarks & Signature


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:-To Display The Application Program Screen
Student Roll no:- Student Name:- Semester/Batch:-6

Aim: Write A Java Applet To Display The Application Program Screen i.e. Calculator.
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++)
{

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
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);
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);

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
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("");
}
else if(str.equals("mul"))
{
v1=Integer.parseInt(t1.getText());
OP='*';

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
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);
}

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
if(str.equals("clear"))
{
t1.setText("");
}
}
}

Faculty Remarks & Signature


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 Remarks & Signature


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:-Write A XML For Creating DTD


Student Roll no:- Student Name:- Semester/Batch:-6

Aim: Write A XML For Creating DTD, Which Specifies Set Of Rules. Create a CSS/XSL
& Display The Document In A Browser.
Code:
XML Document:
<?xml version="1.0" encoding="UTF-8"?>
<!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="bk001">
<title>The Catcher in the Rye</title>
<author>J.D. Salinger</author>
<publisher>Little, Brown and Company</publisher>
<year>1951</year>
<price>19.99</price>
</book>
CSS Code:
title {
font-size: 24px;

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
font-weight: bold;
text-decoration: underline;
color: #000;
}
author {
font-size: 18px;
font-weight: normal;
color: #666;
}
publisher {
font-size: 18px;
font-weight: normal;
color: #666;
}
year {
font-size: 18px;
font-weight: normal;
color: #666;
}
price {
font-size: 18px;
font-weight: bold;
color: #000;
}
XSL Document:
<?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>

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
<head>
<title>Book Details</title>
<link rel="stylesheet" type="text/css" href="book.css"/>
</head>
<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>

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
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: $<xsl:value-of select="."/>
</p>
</xsl:template>
</xsl:stylesheet>

Faculty Remarks & Signature


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 Remarks & Signature


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:-To Illustrate JDBC Connectivity


Student Roll no:- Student Name:- Semester/Batch:-6

Aim: Program To Illustrate JDBC Connectivity.


Code:
import java.sql.*;
public class FirstExample {
static final String DB_URL = "jdbc:mysql://localhost/TUTORIALSPOINT";
static final String USER = "guest";
static final String PASS = "guest123";
static final String QUERY = "SELECT id, first, last, age FROM Employees";
public static void main(String[] args) {
try(Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(QUERY);) {
while (rs.next()) {
System.out.print("ID: " + rs.getInt("id"));
System.out.print(", Age: " + rs.getInt("age"));
System.out.print(", First: " + rs.getString("first"));
System.out.println(", Last: " + rs.getString("last"));
}
}
catch (SQLException e) {
e.printStackTrace();
}
}
}

Faculty Remarks & Signature


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 Remarks & Signature


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:-Implement A Simple Servlet Book Query


Student Roll no:- Student Name:- Semester/Batch:-6

Aim: Design And Implement A Simple Servlet Book Query With The Help Of JDBC &
SQL.
Code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class BookQueryServlet extends HttpServlet {

public void doPost(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();

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

Connection conn = null;


Statement stmt = null;
ResultSet rs = null;

try {
Class.forName("com.mysql.jdbc.Driver");

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
conn = DriverManager.getConnection("jdbc:mysql://localhost/mydatabase",
"username", "password");
stmt = conn.createStatement();
String sql = "SELECT * FROM books WHERE title LIKE '%" + searchTerm + "%' OR
author LIKE '%" + searchTerm + "%'";
rs = stmt.executeQuery(sql);

out.println("<html>");
out.println("<head>");
out.println("<title>Book Query Results</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Book Query Results</h1>");
out.println("<table>");
out.println("<tr><th>ID</th><th>Title</th><th>Author</th><th>Price</th></tr>");

while (rs.next()) {
int id = rs.getInt("id");
String title = rs.getString("title");
String author = rs.getString("author");
double price = rs.getDouble("price");
out.println("<tr><td>" + id + "</td><td>" + title + "</td><td>" + author + "</td><td>"
+ price + "</td></tr>");
}

out.println("</table>");
out.println("</body>");
out.println("</html>");

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
} catch (SQLException ex) {
out.println("Error: " + ex.getMessage());
} catch (ClassNotFoundException ex) {
out.println("Error: " + ex.getMessage());
} finally {
try {
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (conn != null) conn.close();
} catch (SQLException ex) {
out.println("Error: " + ex.getMessage());
}
}

Faculty Remarks & Signature


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 Remarks & Signature


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:-Develop A Static Web Page Using JSP
Student Roll no:- Student Name:- Semester/Batch:-6

Aim: Install Tomcat Web Server And Develop A Static Web Page Using JSP For Book
Web Site.
Code:
Installing Tomcat Web Server:
1. Download the latest version of Tomcat from the official Apache Tomcat website.
2. Extract the downloaded file into a folder of your choice.
3. Set the JAVA_HOME environment variable to the path of your Java installation.
4. Open a command prompt and navigate to the bin folder inside the Tomcat directory.
5. Run the startup.bat file to start the Tomcat server.
6. Open a web browser and navigate to http://localhost:8080/ to confirm that Tomcat is
running.
7. To stop the server, run the shutdown.bat file in the bin folder.
You can now deploy your web applications to Tomcat by placing them in the webapps
folder inside the Tomcat directory.
JSP Code:
<!DOCTYPE html>
<html>
<head>
<title>My Book Site</title>
</head>
<body>
<header>
<h1>Welcome to My Book Site</h1>
</header>

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering

<section>
<h2>Featured Books</h2>
<ul>
<li>
<a href="#">Book Title 1</a>
<p>Author: John Smith</p>
<p>Price: $9.99</p>
</li>
<li>
<a href="#">Book Title 2</a>
<p>Author: Jane Doe</p>
<p>Price: $12.99</p>
</li>
<li>
<a href="#">Book Title 3</a>
<p>Author: Bob Johnson</p>
<p>Price: $7.99</p>
</li>
</ul>
</section>

<section>
<h2>Top Categories</h2>
<ul>
<li><a href="#">Fiction</a></li>
<li><a href="#">Non-fiction</a></li>
<li><a href="#">Mystery</a></li>
<li><a href="#">Thriller</a></li>

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
<li><a href="#">Romance</a></li>
</ul>
</section>

<section>
<h2>About Us</h2>
<p>We are a book website that offers a wide selection of books in various
categories. Our goal is to provide a user-friendly experience for our customers and to
make it easy for them to find the books they want.</p>
</section>

<footer>
<p>&copy; 2023 My Book Site</p>
</footer>
</body>
</html>

Faculty Remarks & Signature


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 Remarks & Signature


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:-To create Cookie
Student Roll no:- Student Name:-

Semester/Batch:-6

Aim: Assume Four Users User1, User2, User3 And User4 Having Password Pwd1,
Pwd2, Pwd3 And Pwd4 Respectively.
a. Create a Cookie and add these four user id’s and passwords to this Cookie.
b. Read the user id and passwords entered in the Login form and authenticate with the
values available in the cookies.
Code:
A. Cookie Creation:
import javax.servlet.http.Cookie;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CreateCookie extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {
Cookie user1Cookie = new Cookie("user1", "pwd1");
Cookie user2Cookie = new Cookie("user2", "pwd2");
Cookie user3Cookie = new Cookie("user3", "pwd3");
Cookie user4Cookie = new Cookie("user4", "pwd4");

response.addCookie(user1Cookie);

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
response.addCookie(user2Cookie);
response.addCookie(user3Cookie);
response.addCookie(user4Cookie);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("<h3>Cookies created successfully</h3>");
out.println("</body></html>");
}
}
B. Authentication:
<%@ page import="javax.servlet.http.Cookie" %>

<%
String userId = request.getParameter("userId");
String password = request.getParameter("password");
Cookie[] cookies = request.getCookies();
boolean authenticated = false;

if (cookies != null) {
for (Cookie cookie : cookies) {
String name = cookie.getName();
String value = cookie.getValue();

if (name.equals(userId) && value.equals(password)) {


authenticated = true;
break;
}
}
}

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
if (authenticated) {
out.println("Login successful!");
} else {
out.println("Login failed!");
}
%>

Faculty Remarks & Signature


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 Remarks & Signature


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:-Write A JSP Which Insert The Details Of 3-4 User
Student Roll no:- Student Name:- Semester/Batch:-6

Aim: Write A JSP Which Insert The Details Of 3-4 Users Who Register With The
Website By Using Registration Form. Authenticate The User When He Submits The
Login Form Using The Username And Password From The Database.
Code:
<%@ page import="java.sql.*" %>
<%
String url = "jdbc:mysql://localhost:3306/mydatabase"; // replace with your MySQL
database name
String user = "root"; // replace with your MySQL username
String password = "password"; // replace with your MySQL password

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


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

if (username != null && password != null && fullname != null && email != null) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, user, password);
Statement stmt = con.createStatement();
String sql = "INSERT INTO users (username, password, fullname, email) VALUES
('" + username + "', '" + password + "', '" + fullname + "', '" + email + "')";
stmt.executeUpdate(sql);
stmt.close();

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}

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


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

if (loginUsername != null && loginPassword != null) {


try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, user, password);
Statement stmt = con.createStatement();
String sql = "SELECT * FROM users WHERE username = '" + loginUsername + "'
AND password = '" + loginPassword + "'";
ResultSet rs = stmt.executeQuery(sql);
if (rs.next()) {
out.println("Authentication successful.");
} else {
out.println("Authentication failed.");
}
rs.close();
stmt.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
%>

Faculty Remarks & Signature


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)
Department of Computer Science and Engineering
<html>
<head>
<title>Registration and Login Example</title>
</head>
<body>
<h1>Registration Form</h1>
<form method="post" action="">
<label>Username:</label><input type="text" name="username"><br>
<label>Password:</label><input type="password" name="password"><br>
<label>Full Name:</label><input type="text" name="fullname"><br>
<label>Email:</label><input type="text" name="email"><br>
<input type="submit" value="Register">
</form>
<h1>Login Form</h1>
<form method="post" action="">
<label>Username:</label><input type="text" name="loginUsername"><br>
<label>Password:</label><input type="password" name="loginPassword"><br>
<input type="submit" value="Login">
</form>
</body>
</html>

Faculty Remarks & Signature


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 Remarks & Signature

You might also like