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

Final File

The document outlines practical assignments for students in the Department of Computer Science and Engineering at Krishna Engineering College, affiliated with Dr. APJ Abdul Kalam Technical University. It includes tasks such as creating HTML forms, Java applets, and JDBC connectivity programs, along with example codes for each practical. The document serves as a guideline for students to develop their programming skills in web development and database management.

Uploaded by

Rishabh Jain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Final File

The document outlines practical assignments for students in the Department of Computer Science and Engineering at Krishna Engineering College, affiliated with Dr. APJ Abdul Kalam Technical University. It includes tasks such as creating HTML forms, Java applets, and JDBC connectivity programs, along with example codes for each practical. The document serves as a guideline for students to develop their programming skills in web development and database management.

Uploaded by

Rishabh Jain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

(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: _______________________

Faculty In-Charge:

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


KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr APJ Abdul Kalam Technical University, Lucknow)

Department of Computer Science & Engineering

INDEX

S No. Practical Name Date Signature


1. Write HTML/Java scripts to display your CV in navigator,
your Institute website, Department Website and Tutorial
website for specific subject.

2. Write an HTML program to design an entry form of


student details and send it to store at database server like
SQL, Oracle or MS Access.

3. Write programs using Java script for Web Page to display


browsers information.

4. Write a Java applet to display the Application Program


screen i.e. calculator and other.

5. Write a program in XML for creation of DTD, which


specifies set of rules. Create a style sheet in CSS/ XSL &
display the document in internet explorer.

6. Program to illustrate JDBC connectivity. Program for


maintaining database by sending queries. Design and
implement a simple servlet book query with the help of
JDBC & SQL. Create MS Access Database, Create on
ODBC link.
KRISHNA ENGINEERING COLLEGE
(Approved by AICTE & Affiliated to Dr APJ Abdul Kalam Technical University, Lucknow)

Department of Computer Science & Engineering

7. Install TOMCAT web server and APACHE. Access the


above developed static web pages for books web site,
using these servers by putting the web pages developed.

8. Assume four users user1, user2, user3 and user4 having


the passwords pwd1, pwd2, pwd3 and pwd4 respectively.
Write a servlet for doing the following. Create a Cookie
and add these four-user id’s and passwords to this Cookie.
2. Read the user id and passwords entered in the Login
form and authenticate with the values available in the
cookies.

9. Install a database (MySQL or Oracle). Create a table


which should contain at least the following fields: name,
password, email-id, phone number Write a java
program/servlet/JSP to connect to that database and extract
data from the tables and display them. Insert the details of
the users who register with the web site, whenever a new
user clicks the submit button in the registration page.

10. Write a JSP which insert the details of the 3 or 4 users who
register with the web site by using registration form.
Authenticate the user when he submits the login form
using the user’s name and password from the database.

11. Design and implement a simple shopping cart example


with session tracking API.
PRACTICAL 1
Write HTML/Java scripts to display your CV in navigator, your Institute website,
Department Website and Tutorial website for specific subject.
Code

<!DOCTYPE html>
<html>
<head>
<title>My Personal Page</title>
</head>
<body>
<h1>Welcome to My Personal Page</h1>
<nav>
<ul>
<li><a href="cv.pdf" target="_blank">My CV</a></li>
<li><a href="http://www.myinstitute.edu" target="_blank">Institute
Website</a></li>
<li><a href="http://www.myinstitute.edu/mydepartment"
target="_blank">Department Website</a></li>
<li><a href="http://www.tutorialwebsite.com/mysubject"
target="_blank">My Subject Tutorial</a></li>
</ul>
</nav>
</body>
</html>

Output
PRACTICAL 2
Write an HTML program to design an entry form of student details and send it to store at
database server like SQL, Oracle or MS Access.
Code

<!DOCTYPE html>
<html>
<head>
<title>Student Entry Form</title>
</head>
<body bgcolor="white" bolder="2">
<form action="register.jsp" name="StudentRegistration" method=”post”>
<table cellpadding="2" width="50%" border="2" align="center"
cellspacing="2">
<tr>
<td colspan=2>
<center>
<font size=4><b>Student Registration Form</b></font>
</center>
</td>
</tr>
<tr>
<td>Name</td>
<td><input type=text name=textnames id="textname"
size="30"></td>
</tr>
<tr>
<td>Father Name</td>
<td><input type="text" name="fathername" id="fathername"
size="30"></td>
</tr>
<tr>
<td>Permanant Address</td>
<td><input type="text" name="permanantaddress"
id="permanantaddress" size="30"></td>
</tr>
<tr>
<td>Gender</td>
<td><input type="radio" name="Gender" value="male"
size="10">Male
<input type="radio" name="Gender" value="Female"
size="10">Female
</td>
</tr><tr>
<td>City</td>
<td><select name="City">
<option value="-1" selected>select..</option>
<option value="New Delhi">NEW DELHI</option>
<option value="Mumbai">MUMBAI</option>
<option value="Goa">GOA</option>
<option value="Patna">PATNA</option>
</select></td>
</tr>
<tr>
<td>Course</td>
<td><select name="Course">
<option value="-1" selected>select..</option>
<option value="B.Tech">B.TECH</option>
<option value="MCA">MCA</option>
<option value="MBA">MBA</option>
<option value="BCA">BCA</option>
</select></td>
</tr>
<tr>
<td>PinCode</td>
<td><input type="text" name="pincode" id="pincode"
size="30"></td>
</tr>
<tr>
<td>EmailId</td>
<td><input type="text" name="emailid" id="emailid"
size="30"></td>
</tr>
<tr>
<td>DOB</td>
<td><input type="text" name="dob" id="dob" size="30"></td>
</tr>
<tr>
<td>MobileNo</td>
<td><input type="text" name="mobileno" id="mobileno"
size="30"></td>
</tr>
<tr>
<td><input type="reset"></td>
<td colspan="2"><input type="submit" value="Submit Form"
/></td>
</tr>
</table>
</form>
</body>
</html>
Output
PRACTICAL 3
Write programs using Java script for Web Page to display browsers information.
Code

<!DOCTYPE html>
<html>
<head>
<title>Browser Information</title></head>
<body>
<h1>Browser Information</h1>
<p id="info"></p>
<script>
var info = "Browser CodeName: " + navigator.appCodeName + "<br>" +
"Browser Name: " + navigator.appName + "<br>" +
"Browser Version: " + navigator.appVersion + "<br>" +
"Cookies Enabled: " + navigator.cookieEnabled + "<br>" +
"Browser Language: " + navigator.language + "<br>" +
"Browser Online: " + navigator.onLine + "<br>" +
"Platform: " + navigator.platform + "<br>" +
"User-agent header: " + navigator.userAgent;
document.getElementById("info").innerHTML = info;
</script>
</body>
</html>

Output
PRACTICAL 4
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.*;
/*
<applet code="Cal" width=300 height=300>
</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);
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("");
} 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("");
}

}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public int getV1() {
return v1;
}
public void setV1(int v1) {
this.v1 = v1;
}
public int getV2() {
return v2;
}
public void setV2(int v2) {
this.v2 = v2;
}
public int getResult() {
return result;
}
public void setResult(int result) {
this.result = result;
}
public TextField getT1() {
return t1;
}
public void setT1(TextField t1) {
this.t1 = t1;
}
public Button[] getB() {
return b;
}
public void setB(Button[] b) {
this.b = b;
}
public Button getAdd() {
return add;
}
public void setAdd(Button add) {
this.add = add;
}
public Button getSub() {
return sub;
}
public void setSub(Button sub) {
this.sub = sub;
}
public Button getMul() {
return mul;}
public void setMul(Button mul) {
this.mul = mul;}
public Button getDiv() {
return div;
}
public void setDiv(Button div) {
this.div = div;

}
public Button getClear() {
return clear;}
public void setClear(Button clear) {
this.clear = clear;
}
public Button getMod() {
return mod;}
public void setMod(Button mod) {
this.mod = mod;}
public Button getEQ() {
return EQ;}
public void setEQ(Button eQ) {
EQ = eQ;}
public char getOP() {
return OP;}
public void setOP(char oP) {
OP = oP;
}
}
Output
PRACTICAL 5
Write a program in XML for creation of DTD, which specifies set of rules. Create a style
sheet in CSS/ XSL & display the document in internet explorer.
Code

<!--1. XML-->
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd>
<title>FOREVER</title>
<artist>
<b>JUSTIN BIEBER</b>
</artist><br>
<country>CANADA</country><br>
<company>COLUMBIA</company><br>
<price>10.69</price><br>
<year>2020</year><br>
</cd>
<cd>
<br>
<title>LIFE IS WORTH IVING</title><br>
<artist>
<b>JUSTIN BIEBER</b>
</artist><br>
<country>CAN</country><br>
<company>CBS Records</company><br>
<price>9.90</price><br>
<year>2016</year><br>
</cd>
</catalog>
<!--XSL-->
<html>
<body>
<h2>
<i>My Song Collection</i></h2>
<table border="1">
<tr bgcolor="#9f69f">
<th style="text-align:left">Title</th>
<th style="text-align:left">Artist</th></tr>
<xsl:for-each select="catalog/cd">
<tr>
<td>
<xsl:value-of select="title" /></td>
<td>
<xsl:value-of select="artist" /></td></tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<!--2.XML-->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note SYSTEM "Note.dtd">
<note><br>
<heading>Remember,<br>
<b>LIFE</b> is too short, so</heading>
<body>
<b>LIVE IN THE MOMENT</b>
</body>
</note>
<!--DTD-->
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>

Output
PRACTICAL 6
Program to illustrate JDBC connectivity. Program for maintaining database by sending
queries. Design and implement a simple servlet book query with the help of JDBC & SQL.
Create MS Access Database, Create on ODBC link.
Code

//STEP 1. Import required packages


import java.sql.*;

public class FirstExample {


// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/EMP";
// Database credentials
static final String USER = "username";
static final String PASS = "password";

public static void main(String[] args) {


Connection conn = null;
Statement stmt = null;
try {
// STEP 2: Register JDBC driver
Class.forName("com.mysql.jdbc.Driver");
// STEP 3: Open a connection
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
// STEP 4: Execute a query
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql;
sql = "SELECT id, first, last, age FROM Employees";
ResultSet rs = stmt.executeQuery(sql);
// STEP 5: Extract data from result set
while (rs.next()) {
// Retrieve by column name
int id = rs.getInt("id");
int age = rs.getInt("age");
String first = rs.getString("first");
String last = rs.getString("last");
// Display values
System.out.print("ID: " + id);
System.out.print(", Age: " + age);
System.out.print(", First: " + first);
System.out.println(", Last: " + last);
}
// STEP 6: Clean-up environment
rs.close();
stmt.close();
conn.close();
} catch (SQLException se) {
// Handle errors for JDBC
se.printStackTrace();
} catch (Exception e) {
// Handle errors for Class.forName
e.printStackTrace();
} finally {
// finally block used to close resources
try {
if (stmt != null)
stmt.close();
} catch (SQLException se2) {

} // nothing we can do
try

{
if (conn != null)
conn.close();
} catch (SQLException se) {
se.printStackTrace();
} // end finally try
} // end try
System.out.println("Goodbye!");
}// end main
}// end FirstExample

Servlet And
JDBC
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class JDBCServlet extends HttpServlet {
public void doGet(HttpServletRequest inRequest,
HttpServletResponse outResponse) throws ServletException,
IOException {
PrintWriter out = null;
Connection connection = null;
Statement statement;
ResultSet rs;
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager
.getConnection("jdbc:mysql://localhost/products");
statement = connection.createStatement();
outResponse.setContentType("test/html");
out = outResponse.getWriter();
rs = statement.executeQuery("SELECT ID, title, price FROM
product");
out.println("<HTML><HEAD><TITLE>Products</TITLE></HEAD>");
out.println("<BODY>");
out.println("<UL>");
while (rs.next()) {
out.println("<LI>" + rs.getString("ID") + " "
+ rs.getString("title") + " " + rs.getString("price"));
}
out.println("</UL>");
out.println("</BODY></HTML>");
} catch (ClassNotFoundException e) {
out.println("Driver Error");
} catch (SQLException e) {
out.println("SQLException: " + e.getMessage());
}
}
public void doPost(HttpServletRequest inRequest,
HttpServletResponse outResponse) throws ServletException,
IOException {
doGet(inRequest, outResponse);
}}
PRACTICAL 7
Install TOMCAT web server and APACHE. Access the above developed static web pages for
books web site, using these servers by putting the web pages developed.
Code

Step 1: Install Apache HTTP Server


1. Download the Apache HTTP Server from the official Apache website.
2. Follow the instructions provided on the website to install the server on your
system.
Step 2: Install Tomcat
1. Download the latest version of Tomcat from the official Tomcat website.
2. Extract the downloaded file to a directory of your choice.
3. Set the CATALINA_HOME environment variable to point to the installation
directory.
Step 3: Deploy Your Web Pages
1. For Apache, copy your static web pages to the htdocs folder in the Apache
installation directory.
2. For Tomcat, create a new folder in the webapps directory in the Tomcat installation
directory. This will be your web application directory. You can name it anything you
like, for example, myapp. Then, inside this directory, create another directory named
ROOT, and copy your static web pages into this ROOT directory.
Step 4: Access Your Web Pages
1. Start the Apache and Tomcat servers.
2. Open a web browser and navigate to http://localhost/ for Apache, and
http://localhost:8080/myapp/ for Tomcat (replace myapp with the name of your
web application directory).
Output
PRACTICAL 8
Assume four users user1, user2, user3 and user4 having the passwords pwd1, pwd2, pwd3
and pwd4 respectively. Write a servlet for doing the following. Create a Cookie and add
these four-user id’s and passwords to this Cookie. 2. Read the user id and passwords entered
in the Login form and authenticate with the values available in the cookies.

Code

Cologin.html
<html>
<head>
<title> login Page </title>
<p style="background:yellow; top:100px; left:250px; position:absolute; ">
</head>
<body>
<form ACTION="clogin">
<label> Login </label>
<input type="text" name="usr" size="20"> <br> <br>
<label> Password </label>
<input type="password" name="pwd" size="20"> <br> <br>
<input type="submit" value="submit">
</form>
</body>
</html>

Cologin1.html
<html>
<head>
<title> login Page </title>
<p style="background:yellow; top:100px; left:250px; position:absolute; ">
</head>
<body>
<form ACTION="clogin1">
<label> Login </label>
<input type="text" name="usr" size="20"> <br> <br>
<label> Password </label>
<input type="password" name="pwd" size="20"> <br> <br>
<input type="submit" value="submit">
</form>
</body>
</html>
Addcook.java:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Addcook extends HttpServlet {
String user, pas;
public void service(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
Cookie c1 = new Cookie("usr1", "suni");
Cookie p1 = new Cookie("pwd1", "ani");
Cookie c2 = new Cookie("usr2", "abc");
Cookie p2 = new Cookie("pwd2", "123");
Cookie c3 = new Cookie("usr3", "def");
Cookie p3 = new Cookie("pwd3", "456");
Cookie c4 = new Cookie("usr4", "mno");
Cookie p4 = new Cookie("pwd4", "789");
res.addCookie(c1);
res.addCookie(p1);
res.addCookie(c2);
res.addCookie(p2);
res.addCookie(c3);
res.addCookie(p3);
res.addCookie(c4);
res.addCookie(p4);
out.println("COOKIE ADDED");
}
}

Clogin.java:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Clogin extends HttpServlet {
String user, pas;
public void service(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
user = req.getParameter("usr");
pas = req.getParameter("pwd");
Cookie[] c = req.getCookies();
for (int i = 0; i < c.length; i++) {
if ((c[i].getName().equals("usr1") && c[i +
1].getName().equals("pwd1")) ||
c[i].getName().equals("usr2") &&
c[i + 1].getName().equals("pwd2")) ||
(c[i].getName().equals("usr3") &&
c[i + 1].getName().equals("pwd3")) ||
(c[i].getName().equals("usr4") &&
c[i + 1].getName().equals("pwd4"))) {
if ((user.equals(c[i].getValue()) && pas.equals(c[i +
1].getValue()))) {
//RequestDispatcher rd=req.getRequestDispatcher("/cart.html");
rd.forward(req, res);
} else {
out.println("YOU ARE NOT AUTHORISED USER ");
//res.sendRedirect("/cookdemo/cologin.html");
}
}
}
}
}

Web.xml:
<web-app>
<servlet>
<servlet name>- him</servlet-name>
<servlet-class>Clogin</servlet-class>
</servlet>
<servlet>
<servlet-name>
htm1</servlet-name>
<servlet-class>Addcook</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>him</servlet-name>
<url-pattern>/clogin</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>him1</servlet-name>
<url-pattern>/clogin1</url-pattern>
</servlet-mapping>
</web-app>
Output
PRACTICAL 9
Install a database (MySQL or Oracle). Create a table which should contain at least the
following fields: name, password, email-id, phone number Write a java program/servlet/JSP
to connect to that database and extract data from the tables and display them. Insert the
details of the users who register with the web site, whenever a new user clicks the submit
button in the registration page.

Code

Registration.html:

<html>
<head>
<title>Registration page</title>
</head>
<body bgcolor="#00FFFf">
<form METHOD="POST" ACTION="register">
<CENTER>
<table>
<center>
<tr>
<td> Username </td>
<td><input type="text" name="usr"> </td>
</tr>
<tr>
<td> Password </td>
<td><input type="password" name="pwd"> </td>
</tr>
<tr>
<td>Age</td>
<td><input type="text" name="age"> </td>
</tr>
<tr>
<td>Address</td>
<td> <input type="text" name="add"> </td>
</tr>
<tr>
<td>email</td>
<td> <input type="text" name="mail"> </td>
</tr>
<tr>
<td>Phone</td>
<td> <input type="text" name="phone"> </td>
</tr>
<tr>
<td colspan=2 align=center> <input type="submit"
value="submit"> </td>
</tr>
</center>
</table>
</form>
</body>

Login.html

<html>

<head>
<title>Registration page</title>
</head>

<body bgcolor=pink>
<center>
<table>
<form METHOD="POST" ACTION="authent">
<tr>
<td> Username </td>
<td><input type="text" name="usr"></td>
</tr>
<tr>
<td> Password </td>
<td> <input type="password" name="pwd"> </td>
</tr>
<tr>
<td align=center colspan="2"><input type="submit"
value="submit"></td>
</tr>
</table>
</center>
</form>
</body>

</html>

Ini.java:
import javax.servlet.*;
import java.sql.*;
import java.io.*;
public class Ini extends GenericServlet {
private String user1, pwd1, email1;
public void service(ServletRequest req, ServletResponse res) throws
ServletException, IOException {
user1 = req.getParameter("user");
pwd1 = req.getParameter("pwd");
email1 = req.getParameter("email");
res.setContentType("text/html");
PrintWriter out = res.getWriter();
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con =
DriverManager.getConnection("jdbc:oracle:thin:@195.100.101.158:1521:cclab",
"scott", "tiger");
PreparedStatement st = con.prepareStatement("insert into personal
values(?,?,?,?,?,?)");
st.setString(1, user1);
st.setString(2, pwd1);
st.setString(3, "25");
st.setString(4, "hyd");
st.setString(5, email1); st.setString(6,"21234");
st.executeUpdate();
con.close();
} catch (SQLException s) {
out.println("not found " + s);
} catch (ClassNotFoundException c) {
out.println("not found " + c);
}}}

web.xml:
<web-app>
<servlet>
<servlet-name>init1</servlet-name>
<servlet-class>Ini</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>init1</servlet-name>
<url-pattern>/regis</url-pattern>
</servlet-mapping>
</web-app>
Output
PRACTICAL 10
Write a JSP which insert the details of the 3 or 4 users who register with the web site by
using registration form. Authenticate the user when he submits the login form using the
user’s name and password from the database.
Code

Login.html:
<html>

<body>
<center>
<h1>XYZ Company Ltd.</h1>
</center>
<table border="1" width="100%" height="100%">
<tr>
<td valign="top" align="center"><br />
<form action="auth.jsp">
<table>
<tr>
<td colspan="2" align="center"><b>Login
Page</b></td>
</tr>
<tr>
<td colspan="2" align="center"><b>&nbsp;</td>
</tr>
<tr>
<td>User Name</td>
<td><input type="text" name="user" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pwd" /></td>
</tr>
<tr>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="2" align="center"><input type="submit"
value="LogIN" /></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>

</html>

Auth.jsp:

<%@page import="java.sql.*;" %>


<html>

<head>
<title>
This is simple data base example in JSP</title>
</title>
</head>

<body bgcolor="yellow">
<%!String uname,pwd;%>
<% uname=request.getParameter("user"); pwd=request.getParameter("pwd");
try {
Class.forName("oracle.jdbc.driver.OracleDriver"); ]
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@195.100.101.158:
1521:CCLAB","scott","tiger");
Statement st=con.createStatement(); ResultSet
rs=st.executeQuery("select name,password from personal
where name='"+uname+"' and password='"+pwd+"'");
if(rs.next())
{
out.println(" Authorized person"); } else { out.println("UnAuthorized person");
} con.close(); } catch(Exception
e){out.println(""+e);} %>
</body>

</html>
Output
PRACTICAL 11
Design and implement a simple shopping cart example with session tracking API.
Code

const express = require('express');


const session = require('express-session');
const redis = require('redis');
const connectRedis = require('connect-redis');
const cors = require('cors');

const RedisStore = connectRedis(session);

//Configure redis client


const redisClient = redis.createClient({
host: 'localhost',
port: 6379
});

redisClient.on('error', (err) => {


console.log('Could not establish a connection with redis. ' + err);
});
redisClient.on('connect', (err) => {
console.log('Connected to redis successfully');
});

// Initialize the Express App


const app = express();

// Use the session middleware


app.use(session({
store: new RedisStore({ client: redisClient }),
secret: 'your-secret-key',
saveUninitialized: false,
resave: false,
cookie: {
secure: false, // if true only transmit cookie over https
httpOnly: false, // if true prevent client side JS from reading the
cookie
maxAge: 1000 * 60 * 10 // session max age in miliseconds
}
}));

app.use(cors());

// Simple route for adding an item to the cart


app.post('/cart/:itemId', (req, res) => {
const itemId = req.params.itemId;
req.session.cart = req.session.cart || {};
req.session.cart[itemId] = (req.session.cart[itemId] || 0) + 1;
res.json(req.session.cart);
});

// Simple route for viewing the cart


app.get('/cart', (req, res) => {
res.json(req.session.cart || {});
});

// Start the server


app.listen(3000, () => console.log('Server is running on port 3000'));

Output

You might also like