Web Tech Lab File A

Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

ALLENHOUSE INSTITUTE OF

TECHNOLOGY
Rooma, Kanpur (U.P.)

DEPARTMENT OF COMPUTER
SCIENCE AND ENGINEERING

WEB TECHNOLOGY LAB FILE

(KCS-652)

Submitted by: Submitted to:


Name: Mr. Saurabh Prasad
Roll No: 21050515300

Branch: CS(AI&ML)
INDEX
S.NO Program Title Performed Submitted Faculty Sign
Date Date
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 sendit to store
at database server like SQL, Oracle or MS
Access.

3. Write programs using Java script for


Web Page to displaybrowsers
information
4. Write programs using Java script for
Web Page to displaybrowsers
information
5.
Writing 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, Compile & execute
JAVA JDVC Socket
7. 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 valuesavailable in
the cookies
8. Write a JSP which insert the details of the 3
or 4 users who register with the web site by
using registration form.
Experiment: 1
Objective:- Write HTML/Java scripts to display your CV in navigator, your Institute website,
Department Website and Tutorial website for specific subject.
Program

<DOCTYPE HTML>

<html>

<body style="background-color:white;">

<div style="position:absolute;top:90px;left:800px;color:red;">

<p> <br><img src= "D:\nitesh document\nitesh\20180828_203145-1.jpg" height =" 150 pt" >

</div>

<div style="padding-left:0px;margin-top:10px; ">

<p style ="font-size:20pt; text-align: right"><a href="https://www.litlucknow.ac.in/"> Lucknow


Institute Of Technology </a></p>

<h1 style="font-size:30pt; text-align:center"><i><span style="color:Black;"><u>Curriculum


Vitae</u></i></h1>

<div style="padding-left:150px;margin-top:3px; ">

<h1 style="font-size:20pt;"><i><span style="color:black;">Nitesh Kumar Dubey</span></i></h1>

<h4>8429745207</br>

[email protected]</br>

mahanandpur,maharajgunj,mirzapur</br>

pin code - 221314</h4>

</div>

<div id="menu" style="background-color:white;width:150px;height:700px;float:left;">

</div>

<div id="content" style="background-color:white;float:left;width:700px;height:1800px;">

<h1 style="font-size:20pt;">Objective</h1>

<p style ="font-size:15pt; font-family:Bell MT">A motivated individual with in-depth knowledge of
languages and development tools, </br>

seeking a position in a growth-oriented company where I can use my skills to the</br>

advantage of the company while having the scope to develop my own skills.</p>

<h1 style="font-size:25pt;">EDUCATION AND QUALIIFICATIONS:</h1>

<table>

<tr>

<th>Qualification</th>

<th>Maximun Marks</th>

<th>Obtained Marks</th>

<th>Division</th>

<th>Institution</th>

<th>Bord/University</th>

</tr

<tr>

<td>b.tech in progress</td>

<td> ----</td>

<td> ----</td>

<td>None</td>

<td>Lucknow Institute of Technology</td>

<td>A.K.T.University </td>

</tr>

<tr>

<td>Diploma</td>

<td>2400</td>

<td>1859</td>

<td>First</td>
<td>Mahatma jyotiba phole gov. polytechnic kaushambi </td>

<td>Board of Technical Education </td>

</tr>

<tr>

<td>12th </td>

<td>500</td>

<td>301</td>

<td> second</td>

<td>K. Lion school varanasi</td>

<td> Central Board of Secondary Education</td>

</tr>

<tr>

<td>MATRIC</td>

<td>600</td>

<td>528</td>

<td>first</td>

<td>Glenhill School Manduadih Varansi</td>

<td>Central Board of Secondary Education </td>

</tr>

</table>

<hr>

<h1 style="font-size:15pt;">TECHNICAL EXPERIENCE:</h1>

Languages: HTML, CSS, Java script, c,c++

Platforms: Windows 10,8,7,XP,98 Linux

Concepts: Networking, operating systems

<hr>
<h1 style="font-size:15pt;">PERSONAL SKILLS:</h1>

1.Honesty<br>

2.Team Spirit<br>

3.Accepting Challenges

<hr>

<h1 style="font-size:15pt;">LANGUAGES:</h1>

hindi, english

<hr>

<h1 style="font-size:15pt;">INTEREST:</h1>

1.learning new programming language</br>

2.Reading books</br>

3.website development

<hr>

<h1 style="font-size:15pt;">REFERENCE:</h1>

Will be provided on demand</pre>

<hr>

<h1>

</div>

</body>

</html>
Experiment: 2
Objective: - 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.

Program: - HTML program


<html>
<head>
<title> Entry form</title>
</head>
<body bgcolor="white">

<center> <font color="Black" size="5%" style="Bell MT" ><center>Entry form of student


details</center></font>

<h3>
<center><table border="2Px" color="white " >
<form action="connect.php" method="post ">
<table><tr><td>
First Name:<br><input type="text" name="First_name"/><br></br>
<align="center">Last Name:<br><input type="text" name="last_name/"></br><br>
Your Email address:<br><input type="text" name="Email"/><br/><br>
Create Password:<br><input type="password" name="password" /><br/><br/>
Confirm Your Password:<br><input type="password" name="password" /><br/><br>
GENDER:<br><br><input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="Female"> Female<br><br>
Birthday:<br><select name="dropdown">
<option value="Month"selected>MM</option>
<option value="1998">jan</option>
<option value="1999">feb</option>
<option value="2000">mar</option>
<option value="2001">april</option>
<option value="2002">may</option>
<option value="2003">june</option></select>
<select name="dropdown">
<option value="DD">DD</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option></select>
<select name="dropdown">
<option value="yy">YYYY </option>
<option value="1998">1998</option>
<option value="1997">1997</option>
<option value="1996">1997</option>
<option value="1995">1997</option>
<option value="1994">1997</option>
<option value="1993">1996</option></select><br/></br>
Mobile Number:<br><input type="text" name="mobile_number"></br><br>
Location:<br><input type="text" name="location" /><br/><br>
<input type="submit" name="submit" value="Submit" />
<input type="reset" name="reset" value="Reset" /></h1></td></tr></table></form>
</table>
</center>
</body>
</html>

Php connectivity program


<?php
$firstName =$_Post{['First_name'];
$last_name =$_Post{['last_name'];
$Email =$_Post{['Email'];
$password =$_Post{['password'];
$gender =$_Post{['gender'];
$mobile_number =$_Post{['mobile_number'];
$location =$_Post{['location'];

//Database connection
$conn = new mysqli('localhost' ,'root','','test');
if($conn-> connect_error){
die ('connection Failed :' .$conn->connect_error );
}else{
$stmt = $conn -> Prepare("insert into registration (First_name,last_name,Email,Password,
gender, mobile_number, location)values(?,?,?,?,? ,?)");
$stmt ->bind_param("ssssi",$First_name,$last_name,$Email,$password,$gender,
$mobile_number,$location);
$stmt ->execute();
echo "data store successfully ... ";
$stmt -> close();
$conn->close();
}

?>
Experiment: 3
Objective:- Write programs using Java script for Web Page to displaybrowsers
information.

Program:-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Google map using Java script</title>
<script language=javascript>
function show()
{
document.write("Name "+navigator.appName+"<br>");
document.write("Version "+navigator.appVersion +"<br>");
document.write("Codename " +navigator.appCodeName +"<br>");
document.write("Cookie enable"+navigator.cookieEnabled +"<br>");
document.write("Java Enable"+navigator.javaEnabled +"<br>");
document.write("Mime type"+navigator.mimeTypes +"<br>");
document.write("Platform"+navigator.platform +"<br>");
document.write("Plug ins"+navigator.plugins +"<br>");
document.write("System Language"+navigator.systemLanguage +"<br>");
document.write("User language"+navigator.userAgent +"<br>");
document.write("User Agent"+navigator.userAgent +"<br>");
}
</script>
</head>
<body>
<form id="form1">
<div>
<input id="Button1" type="button" value="Click me" onclick="show()" />
</div>
</form>
</body>
</html>

Result:-
Experiment: 4
Objective:- Write programs using Java script for Web Page to displaybrowsers information
Program:-
<html>
<head>
<style>
.btn
{
width:55px;
height:50px;
background-color:green;
color:white;
font-size:25px;
margin:8px;
border-radius:15px;
}
</style>
<script>
var num1,num2,result,op;
function manageBtn(x)
{
var asc=x.charCodeAt(0); // ASCII
var tx=document.getElementById("txt");
if(asc>=48 && asc<=57)
{
if(tx.value=="0")
tx.value="";
tx.value=tx.value+x;
}
else if(asc==46)
{
var isPointFound=false;
var a=tx.value;
for(i=0;i<a.length;i++)
{
var ch=a.charAt(i);
if(ch=='.')
isPointFound=true;
}
if(isPointFound==false)
txt.value=txt.value+".";
}
else if(asc==67)
{
var a=tx.value;
tx.value=a.substring(0,a.length-1);
if(tx.value.length==0)
tx.value="0";
}
else if(asc==65)
{
txt.value="0";
}
else if(asc==43 || asc==45 || asc==42 || asc==47 || asc==37)
{
num1=parseFloat(tx.value);
op=x;
tx.value="0";
}
else if(asc==61)
{
num2=parseFloat(tx.value);
switch(op)
{
case "+":
result=num1+num2;
break;
case "-":
result=num1-num2;
break;
case "*":
result=num1*num2;
break;
case "/":
result=num1/num2;
break;
case "%":
result=(num1*100)/num2;
break;
default:
alert("Invalid Operation");
}
tx.value=result;
}
}
</script>
</head>
<body>
<div style="width:300px;
border-radius:25px;height:400px;background-color:pink;margin:0px auto;border:2px dotted
blue;padding:15px;">
<input type="text" id="txt" style="width:95%;height:40px;font-size:30px; border-radius:15px"
value="0" />
<input type="button" value="9" class="btn"
onclick="manageBtn(this.value)" />
<input type="button" value="8"
onclick="manageBtn(this.value)" class="btn" />
<input type="button" value="7"
onclick="manageBtn(this.value)" class="btn" />
<input type="button" value="C" onclick="manageBtn(this.value)"
class="btn" />
<input type="button" value="6"
onclick="manageBtn(this.value)"
class="btn" />
<input type="button" value="5"
onclick="manageBtn(this.value)" class="btn" />
<input type="button" value="4"
onclick="manageBtn(this.value)" class="btn" />
<input type="button" value="+"
onclick="manageBtn(this.value)" class="btn" />
<input type="button" value="3"
onclick="manageBtn(this.value)" class="btn" />
<input type="button" value="2"
onclick="manageBtn(this.value)" class="btn" />
<input type="button" value="1"
onclick="manageBtn(this.value)" class="btn" />
<input type="button" value="-"
onclick="manageBtn(this.value)" class="btn" />
<input type="button" value="00"
onclick="manageBtn(this.value)" class="btn" />
<input type="button" value="0"
onclick="manageBtn(this.value)" class="btn" />
<input type="button" value="."
onclick="manageBtn(this.value)" class="btn" />
<input type="button" value="*"
onclick="manageBtn(this.value)" class="btn" />
<input type="button" value="AC"
onclick="manageBtn(this.value)" class="btn" />
<input type="button" value="="
onclick="manageBtn(this.value)" class="btn" />
<input type="button" value="%"
onclick="manageBtn(this.value)" class="btn" />
<input type="button" value="/"
onclick="manageBtn(this.value)" class="btn" />
<p style="text-align:center;color:Black;font-size:15px;font-weight:bold">
Developed By: Mr. Nitesh Kumar Dubey
</p>
</div>
</body>
</html>
Result:-
Experiment: 5
Objective: - Writing 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.
Program:- XML code
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="D:\workshop\rule.css"?>
<books>
<heading>Welcome to XML file </heading>
<book>
<title>Title -: Web Programming</title>
<author>Author -: Chrisbates</author>
<publisher>Publisher -: Wiley</publisher>
<edition>Edition -: 3</edition>
<price> Price -: 300</price>
</book>
<book>
<title>Title -: Internet world-wide-web</title>
<author>Author -: Ditel</author>
<publisher>Publisher -: Pearson</publisher>
<edition>Edition -: 3</edition>
<price>Price -: 400</price>
</book>
<book>
<title>Title -: Computer Networks</title>
<author>Author -: Foruouzan</author>
<publisher>Publisher -: Mc Graw Hill</publisher>
<edition>Edition -: 5</edition>
<price>Price -: 700</price>
</book>
<book>
<title>Title -: DBMS Concepts</title>
<author>Author -: Navath</author>
<publisher>Publisher -: Oxford</publisher>
<edition>Edition -: 5</edition>
<price>Price -: 600</price>
</book>
<book>
<title>Title -: Linux Programming</title>
<author>Author -: Subhitab Das</author>
<publisher>Publisher -: Oxford</publisher>
<edition>Edition -: 8</edition>
<price>Price -: 300</price>
</book>
</books>
CSS code
books {
color: white;
background-color : gray;
width: 100%;
}

heading {
color: green;
font-size : 40px;
background-color : powderblue;
}
heading, title, author, publisher, edition, price {
display : block;
}
title {
font-size : 25px;
font-weight : bold;
}
Result: -
Experiment: 6
Objective:- 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, Compile & execute JAVA JDVC
Socket.

Program for JDBC:-


import java.sql.*;
class MysqlCon{
public static void main(String args[]){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/sonoo","root","root");
//here sonoo is database name, root is username and password
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from emp");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
con.close();
} catch(Exception e){ System.out.println(e);}
}
}
Program for maintaining database by sending queries
package com.java2novice.jdbc;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.sql.Statement;

public class MyQueryUpdate {

public static void main(String[] args) {

Connection con = null;


Statement stmt = null;

try {

Class.forName("oracle.jdbc.driver.OracleDriver");

con = DriverManager.
getConnection("jdbc:oracle:thin:@<hostname>:<port num>:<DB name>"

,"user","password");

stmt = con.createStatement();
String query = "update table emp set salary=2000 where empid=200";

//count will give you how many records got updated

int count = stmt.executeUpdate(query);

System.out.println("Updated queries: "+count);


} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

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

// TODO Auto-generated catch block

e.printStackTrace();

} finally{

try{

if(stmt != null) stmt.close();

if(con != null) con.close();


} catch(Exception ex){}

Design and implement a simple servlet book query with the help of JDBC & SQL
 Step 1: Creation of Database and Table in MySQL
As soon as jar file is placed in the folder, create a database and table in MySQL,

mysql> create database demoprj;


Query OK, 1 row affected (4.10 sec)
mysql> use demoprj
Database changed

mysql> create table demo(id int(10), string varchar(20));


Query OK, 0 rows affected (1.93 sec)

mysql> desc demo;


Field type Null key Default Extra

id Int(10) yes NULL

string Varchar(20) yes NULL

2 rows in set (0.40 sec)


 Step 2: Implementation of required Web-pages
Create a form in HTML file, where take all the inputs required to insert data into the
database. Specify the servlet name in it, with the POST method as security is important
aspects in database connectivity.

<!DOCTYPE html>
<html>
<head>
<title>Insert Data</title>
</head>
<body>
<!-- Give Servlet reference to the form as an instances
GET and POST services can be according to the problem statement-->
<form action="./InsertData" method="post">
<p>ID:</p>
<!-- Create an element with mandatory name attribute,
so that data can be transfer to the servlet using getParameter() -->
<input type="text" name="id"/>
<br/>
<p>String:</p>
<input type="text" name="string"/>
<br/><br/><br/>
<input type="submit"/>
</form>
</body>
</html>

Create MS Access Database, Create on ODBC link, Compile & execute JAVA JDVC Socket.
package javaapplication1;

import java.sql.*;
public class MSaccess_archive {
public static void main(String[] args) {

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// set this to a MS Access DB you have on your machine
String filename = "mdbTEST.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database+= filename.trim() + ";DriverID=22;}"; // add on to the end
// now we can get the connection from the DriverManager
Connection con = DriverManager.getConnection( database ,"","");

Statement stmt = con.createStatement();

stmt.execute("select * from student"); // execute query in table student

ResultSet rs = stmt.getResultSet(); // get any Result that came from our query

if (rs != null)
while ( rs.next() ){

System.out.println("Name: " + rs.getInt("Age") + " ID: "+rs.getString("Course"));


}

stmt.close();
con.close();
}
catch (Exception err) {
System.out.println("ERROR: " + err);
}
}

}
Experiment: 7
Objective:- 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 valuesavailable in the cookies.
Program for create cookies and authenticate during user id and password enterd
login.php
<html>
<body>
<form method=”POST” action=”setcookie.php”>
username:<input type=”text” name=”uname” id=”uname”/><br/>
password:<input type=”password” name=”pwd” id=”pwd”/><br/>
<input type=”submit” value=”submit”>
</form>
</body>
</html>

setcookie.php
<?php
setcookie(“mycookie1[user1]”,”pwd1″,time()+30);
setcookie(“mycookie1[user2]”,”pwd2″,time()+30);
setcookie(“mycookie1[user3]”,”pwd3″,time()+30);
setcookie(“mycookie1[user4]”,”pwd4″,time()+30);
$username=$_POST[‘uname’];
$passwd=$_POST[‘pwd’];
header(“location:authentication.php?uname=”.$username.”&pwd=”.$passwd);
?>
<html>
<head>
<title>
autheniticationthrrough cookies</title>
</head>
<body>
</body>
</html>
authentication.php
<?php
$username=$_GET[‘uname’];
$passwd=$_GET[‘pwd’];
$status=”no”;
if(isset($_COOKIE[‘mycookie1’]))
{
foreach($_COOKIE[‘mycookie1′] as $key=> $value)
{
if(($key==trim($username)) && ($value==$passwd))
{
$status=”yes”;
echo”welcometo “.$key;
break;
}
else
{
$status=”no”;
}
}
}
echo “<br><br><br><br><br><a href=’logout.php’>logout</a
if($status==”no”)
header(“Location:fail.php”);
?>
fail.php
<?php
echo “user username and or password invalid”;
?>

logout.php
<?php
setcookie(“mycookie1[user1]”,”pwd1″,time()-30);
setcookie(“mycookie1[user2]”,”pwd2″,time()-30);
setcookie(“mycookie1[user3]”,”pwd3″,time()-30);
setcookie(“mycookie1[user4]”,”pwd4″,time()-30);
header(“Location:login.php”);
?>
Experiment: 8
Objective: - 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 name and password from the database.
Program :-
Index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Example</title>
</head>
<body>
<form method="post" action="login.jsp">
<center>
<table border="1" width="30%" cellpadding="3">
<thead>
<tr>
<th colspan="2">Login Here</th>
</tr>
</thead>
<tbody>
<tr>
<td>User Name</td>
<td><input type="text" name="uname" value="" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pass" value="" /></td>
</tr>
<tr>
<td><input type="submit" value="Login" /></td>
<td><input type="reset" value="Reset" /></td>
</tr>
<tr>
<td colspan="2">Yet Not Registered!! <a
href="reg.jsp">Register Here</a></td>
</tr>
</tbody>
</table>
</center>
</form>
</body> </html>
Reg.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Registration</title></head>
<body>
<form method="post" action="registration.jsp">
<center>
<table border="1" width="30%" cellpadding="5">
<thead>
<tr>
<th colspan="2">Enter Information Here</th>
</tr>
</thead>
<tbody>
<tr>
<td>First Name</td>
<td><input type="text" name="fname" value="" /></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lname" value="" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" value="" /></td>
</tr>
<tr>
<td>User Name</td>
<td><input type="text" name="uname" value="" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pass" value="" /></td>
</tr>
<tr>
<td><input type="submit" value="Submit" /></td>
<td><input type="reset" value="Reset" /></td>
</tr>
<tr>
<td colspan="2">Already registered!! <a href="index.jsp">Login
Here</a></td>
</tr>
</tbody>
</table>
</center>
</form>
</body>
</html>
registration.jsp
<%@ page import ="java.sql.*" %>
<%
String user = request.getParameter("uname");
String pwd = request.getParameter("pass");
String fname = request.getParameter("fname");
String lname = request.getParameter("lname");
String email = request.getParameter("email");
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/dbname",
"root", "dbpass");
Statement st = con.createStatement();
//ResultSet rs;
int i = st.executeUpdate("insert into members(first_name, last_name, email,
uname, pass, regdate) values ('" + fname + "','" + lname + "','" + email + "','"
+ user + "','" + pwd + "', CURDATE())");
if (i > 0) {
//session.setAttribute("userid", user);
response.sendRedirect("welcome.jsp");
// out.print("Registration Successfull!"+"<a href='index.jsp'>Go to Login</a>");
} else {
response.sendRedirect("index.jsp");
}
%>

welcome.jsp
Registration is Successful.
Please Login Here <a href='index.jsp'>Go to Login</a>
login.jsp
<%@ page import ="java.sql.*" %>
<%
String userid = request.getParameter("uname");
String pwd = request.getParameter("pass");
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/dbname",
"root", "dbpass");
Statement st = con.createStatement();
ResultSet rs;
rs = st.executeQuery("select * from members where uname='" + userid + "'
and pass='" + pwd + "'");
if (rs.next()) {
session.setAttribute("userid", userid);
//out.println("welcome " + userid);
//out.println("<a href='logout.jsp'>Log out</a>");
response.sendRedirect("success.jsp");
} else {
out.println("Invalid password <a href='index.jsp'>try again</a>");
}
%>
success.jsp
<%
if ((session.getAttribute("userid") == null) ||
(session.getAttribute("userid") == "")) {
%>
You are not logged in<br/>
<a href="index.jsp">Please Login</a>
<%} else {
%>
Welcome <%=session.getAttribute("userid")%>
<a href='logout.jsp'>Log out</a>
<%
}
%>
logout.jsp
<%
session.setAttribute("userid", null);
session.invalidate();
response.sendRedirect("index.jsp");
%>

You might also like