1) A web application that takes name and
age from an HTML page. If the age is less than 18, it should send a page with
“helloo <name>, you are not authorized to visit this site” message
, where <name> should be replaced with the entered name. Otherwise it
should send “welcome <name> to this site “ message.
Sign.html
<html>
<head>
<script type="">
</script>
</head>
<body align="center">
<fieldset
style="width:300px">
<legend> <h3>Sign in</h3>
</legend>
<form name="login"
method="post" action="validate.php">
<br/>
Name
: <input type="text"
name="nam"><br/><br/>
Age :
<input
type="number" name="age"><br/><br/>
<input
type="submit" value="sign in">
</form>
</fieldset>
</body>
</html>
Validate.php
<html>
<head>
<?php
$name= $_POST['nam'];
$age=$_POST['age'];
if
($age>18)
{
echo
'<h2> <font color=green>Welcome '.$name.' to the
website</font></h2>';
}
else
{
echo
'<h2> <font color=red>Hello '.$name.' You are not
authorized.</font></h2>';
}
?>
</head>
</html>
2) A web application takes name as input
and on submit it shows a hello
<name> page where <name> is taken form a request . Its shows a
start time at the right top corner of the page
and provides a logout button. On clicking this button, it should show a
logout page with thank you <name>
message with duration of usage (hint : use session to store name and time)
login.php
<html>
<body>
<script>
function validate() {
var usrName=
document.getElementById("username").value;
if (usrName.length == 0) {
alert("Please enter your Name.");
return false;
}
else{
return true;
}
return
false;
}
</script>
<h2>Welcome</h2>
<fieldset
style="width:250px">
<legend>Enter Your Name</legend>
<form method="POST" action="dashboard.php">
<br/>Name: <input
type="text" name="username"
id="username"><br/>
<br/>
<button type="submit"
onclick="return validate()">Submit</button><br/>
</form>
</fieldset>
</body>
</html>
Dashboard.php
<html>
<body bgcolor="#F08080">
<div width="100%">
<div
style="width:300px;float:left;">
<?php
session_start();
if($_POST)
{
echo "Hello ";
echo
$_SESSION["Username"]=$_POST["username"];
}
?>
</div>
<div
style="width:300px;float:right;">
<?php
$_SESSION["StartDate"]=
date("Y-m-d h:i:sa");
echo date("d-m-Y h:i:sa");
?>
<button
onclick="window.location.href='logout.php'">Logout</button>
</div>
</div>
</body>
</html>
Logout.php
<html>
<body bgcolor="orange">
<div width="100%">
<?php
session_start();
if($_SESSION)
{
echo "Thank you ";
echo $_SESSION["Username"];
$d=strtotime($_SESSION["StartDate"]);
echo "<br/>Your session time is
";
$diff=date_diff(date_create(date("Y-m-d
h:i:sa")),date_create(date("Y-m-d h:i:sa",$d)));
echo " Hours : ". $diff->h .
" Minutes: ". $diff->m . " Seconds ".$diff->s;
session_destroy();
}else
{
echo
"Sorry no sessions found";
}
?>
<br/>
<br/>
<button
onclick="window.location.href='login.php'">Return to Login
Page</button>
</div>
</body>
</html>
3) A Simple calculator web application
that takes two numbers and an operator(+,-,/,*,%) from a HTML page and returns
the result page with the operation performed on the operands.
<html>
<head>
<style>
.k{
background-color:blue;
left:500px;
top:200px;
border:thin
groove;
width:500px;
position:fixed;
height:300px;
text-align:center;
}
</style>
</head>
<body>
<div
class="k">
<p
align="center"><font color="yellow">
<h2>Calculator </h2></font></p>
<form
name="calci">
<input
type="text" name="txt"><br><br/>
<input
type="button" value="1"
onclick="document.calci.txt.value+='1'">
<input
type="button" value="2"
onclick="document.calci.txt.value+='2'">
<input
type="button" value="3"
onclick="document.calci.txt.value+='3'">
<input
type="button" value="+"
onclick="document.calci.txt.value+='+'"><br/><br/>
<input
type="button" value="4"
onclick="document.calci.txt.value+='4'">
<input
type="button" value="5"
onclick="document.calci.txt.value+='5'">
<input
type="button" value="6"
onclick="document.calci.txt.value+='6'">
<input
type="button" value="-" onclick="document.calci.txt.value+='-'"><br/><br/>
<input
type="button" value="7"
onclick="document.calci.txt.value+='7'">
<input
type="button" value="8"
onclick="document.calci.txt.value+='8'">
<input
type="button" value="9"
onclick="document.calci.txt.value+='9'">
<input
type="button" value="*"
onclick="document.calci.txt.value+='*'"><br/><br/>
<input
type="button" value="/"
onclick="document.calci.txt.value+='/'">
<input
type="button" value="0"
onclick="document.calci.txt.value+='0">
<input
type="reset" value="C">
<input
type="button" value="="
onclick="document.calci.txt.value=eval(document.calci.txt.value)">
</div>
</body>
</html>
4)
Write a HTML page that contains a selection box with a list of 5
countries. When the user selects a country, Its capital should be printed next
to the list. Add CSS to customize the properties of the font of the capital
(Color , Bold and Font Size)
<!DOCTYPE html>
<html>
<body bgcolor="cyan">
<center>
<br/><br/><br/>
<font size="20"
color="orange"><i><b><p>Select a Country for
Capital.</p>
<select id="country"
onchange="myCapital()">
<option value="Co" selected="selected">Choose
a Country</option>
<option value="Aus">Australia
<option value="Can">Canada
<option value="US">United States of America
<option value="IN">India
</select>
<p>Captial of Seleted Country
<br/></p>
<p id="demo"></p>
</b></i></font></center>
<script>
function myCapital() {
var x = document.getElementById("country").value;
if(x=="Aus")
{
document.getElementById("demo").innerHTML
= "Capital : Canberra ";
}
else
if(x=="Can")
{
document.getElementById("demo").innerHTML
= "Capital : Ottawa";
}
else
if(x=="US")
{
document.getElementById("demo").innerHTML
= "Capital : Washington, D.C.
";
}
else
if(x=="IN")
{
document.getElementById("demo").innerHTML
= "Capital : Delhi ";
}
else
if(x=="Co")
{
document.getElementById("demo").innerHTML
= "No Country is selected " ;
}
}
</script>
</body>
</html>
5) Write a
HTML page that has one input, which can take multi-line text and a submit button. Once users clicks the
submit button, it should show the number of characters, words and lines in the
text entered using an alert message. Words
are separated with white space and lines are separated with new line
character
<html >
<head>
<title>Number of Characters</title>
<style type="text/css">
#TextArea1
{
height: 153px;
width: 800px;
}
#Button1
{
width: 100px;
height: 50px;
}
</style>
</head>
<body>
<center>
<p>
<textarea id="TextArea1"
name="S1"></textarea></p>
<p>
<button onclick="myFunction()">Submit</button>
<p id="demo">Given Number
of characters are </p>
<p id="demo1">Number
of words </p>
<script>
function myFunction()
{
var str = TextArea1.value;
var n = str.length;
document.getElementById("demo").innerHTML
= n ;
wordcount();
}
function
wordcount()
{
var
str = TextArea1.value;
var
wordCount = str.match(/(\w+)/g).length;
document.getElementById("demo1").innerHTML
= wordCount ;
}
</script>
</center>
</body>
</html>
6)Reading parameters from
html using servelets
Log.html
<body>
<form
action="/readparameters/display" method="post">
User name :<input
type="text" name="usr" />
password :<input
type="password" name="pwd" />
<input
type="submit" />
</form>
</body>
ReadParam.java
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
public class ReadParam
extends HttpServlet
{
public void doPost(HttpServletRequest req,
HttpServletResponse res)
throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter
pw=res.getWriter();
String
User=req.getParameter("usr");
String
pass=req.getParameter("pwd");
pw.println("The Username is <br>"+User);
pw.println("The Password is <br>"+pass);
+
pw.close();
}
}
Web.xml
<web-app>
<servlet>
<servlet-name>ReadSe</servlet-name>
<servlet-class>ReadParam</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ReadSe</servlet-name>
<url-pattern>/display</url-pattern>
</servlet-mapping>
</web-app>
7)Database connectivity in jsp
login.html
<body>
<form action="login.jsp" method="post">
User name :<input
type="text" name="usr" />
password :<input
type="password" name="pwd" />
<input type="submit" />
</form>
</body>
login.jsp
<%@page import
="java.sql.*" %>
<%@page import
="javax.sql.*" %>
<%
String userid=request.getParameter("user");
session.putValue("userid","userid");
String
pwd=request.getParameter("pwd");
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
Statement st= con.createStatement();
ResultSet
rs=st.executeQuery("select * from users where
user_id='"+userid+"'");
if(rs.next())
{
if(rs.getString(2).equals(pwd))
{
out.println("welcome"+userid);
}
else
{
out.println("Invalid password try
again");
}
}
%>
8)JSP program to display current time
Currentdate.jsp
<%@ page
import="java.io.*,java.util.*, javax.servlet.*" %>
<html>
<head>
<title>Display Current Date &
Time</title>
</head>
<body>
<center>
<h1>Display Current Date &
Time</h1>
</center>
<%
Date date = new Date();
out.print( "<h2 align=\"center\">"
+date.toString()+"</h2>");
%>
</body>
</html>
9)Write Java Script that inputs three integers from the user and outputs
their sum, average, largest. Use alert dialog box to display results.
PROGRAM
<html>
<head> <title> MAX </title>
<script language="javascript">
var a,b,c,n1,n2,n3,m1,m2,sum,avg;
a=prompt("enter 1st no="," ");
b=prompt("enter 2nd no="," ");
c=prompt("enter 3rd no="," ");
n1=parseInt(a);
n2=parseInt(b);
n3=parseInt(c);
sum=n1+n2+n3;
avg=sum/3;
m1=Math.max(n1,n2);
m2=Math.max(n3,m1);
alert("the sum is= "+sum);
alert("the avg is= "+m2);
alert("the max no is "+m2);
</script> </head></html>
10)php data base connectivity
<?php
$con=mysql_connect("localhost","root","");
if(!$con)
{
die('could not connect:'.mysql_error());
}
$data=mysql_query("CREATE DATABASE db1",$con);
echo"database created";
mysql_select_db("db1",$con);
$sqll="CREATE TABLE logina(username varchar(15),password
varchar(20),PRIMARY KEY (username))";
mysql_query($sqll,$con);
$sql="INSERT INTO logina values('satwik',15)";
mysql_query($sql,$con);
$sql0="select * from logina";
$w=mysql_query($sql0,$con);
$row=mysql_fetch_array($w);
echo $row['username'];
?>