Sei sulla pagina 1di 111

ROLL NO: 90

PRACTICAL - 1
AIM : Write a program to use basic tag of HTML(title & Footer, Text-Formatting, Text style, List).

Program :

<html>
<head>
<title> This is First Practical by Rakesh Kumar </title>
<style type="text/css">
a
{
color:#000000;
text-decoration:none;
}
a:hover
{
color:#FFFFFF;
text-decoration:none;
}
</style>
</head>

<body style="background-color:#c9c9c9">
<center>
<p><b>Size format of Text!</p></b>
</center>

<h1> H1 Size </h1>


<h2> H2 Size </h2>
<h3> H3 Size </h3>
<h4> H4 Size </h4>
<h5> H5 Size </h5>
<h6> H6 Size </h6>
<hr />

<center>
<p><b>Different types of List!</p></b>
</center>
<div style="background-color:#C2C2C2; width: 100px; -moz-border-radius: 1em">
<ul>
<li> SE </li>
<li> ITA </li>
<li> AOS </li>
<li> ITM </li>
</ul>

KAMESH PATEL 1
ROLL NO: 90

</div>

<div style="background-color:#C2C2C2; width: 100px; margin-left: 110px; margin-top: -96px;


-moz-border-radius: 1em">
<ul type="SQUARE">
<li> SE </li>
<li> ITA </li>
<li> AOS </li>
<li>ITM </li>
</ul>
</div>

<div style="background-color:#C2C2C2; width: 100px; margin-left: 220px; margin-top: -96px;


-moz-border-radius: 1em">
<ol type="A">
<li> SE </li>
<li> ITA </li>
<li> AOS </li>
<li>ITM </li>
</ol>
</div>

<div style="background-color:#C2C2C2; width: 100px; margin-left: 330px; margin-top: -96px;


-moz-border-radius: 1em">
<ol type="a">
<li> SE </li>
<li> ITA </li>
<li> AOS </li>
<li>ITM </li>
</ol>
</div>

<div style="background-color:#C2C2C2; width: 100px; margin-left: 440px; margin-top: -96px;


-moz-border-radius: 1em">
<ol type="I">
<li> SE </li>
<li> ITA </li>
<li> AOS </li>
<li>ITM </li>
</ol>
</div>

<div style="background-color:#C2C2C2; width: 100px; margin-left: 550px; margin-top: -96px;


-moz-border-radius: 1em">
<ol type="i">
<li> SE </li>
<li> ITA </li>

KAMESH PATEL 2
ROLL NO: 90

<li> AOS </li>


<li>ITM </li>
</ol>
</div>
<hr />

<center>
<p><b>Paragraph and Line Break Example!</p></b>
</center>
<big>
<p><b>This is a Paragraph and <br />This is an example of Break tag.</p></b>
</big>
<a href="index.html">Back to Index</a>
</body>
</html>

OUTPUT :

KAMESH PATEL 3
ROLL NO: 90

PRACTICAL - 2
AIM : Write program to create TABLE with ROWSPAN and COLSPAN attribute of TABLE. In
HTML (Prepare Time-Table of your class).

Program :

<html>
<head>
<title>Second Practical</title>
<style type="text/css">
a
{
color:#000000;
text-decoration:none;
}
a:hover
{
color:#FFFFFF;
text-decoration:none;
}
</style>
</head>
<body style="background-color:#C2C2C2">
<center>
<br /><br />
<h3 style="text-decoration:underline">Time Table</h3>
<table border="2" style="margin-top:20px; text-align:center; border-color:#000000">
<tr>
<th>Time/Date</th>
<th>Mon</th>
<th>Tus</th>
<th>Wed</th>
<th>Thus</th>
<th>Fri</th>
</tr>

<tr>
<td rowspan="2">10:40 to 11:40</td>
<td rowspan="2">AOS</td>
<td rowspan="4">B1:PRJ<br />B2:SE<br />B3:ITA<br />B4:ITA<br />B5:PRJ</td>
<td rowspan="2">ISA</td>
<td rowspan="2">AOS</td>
<td rowspan="2">ITA</td>
</tr>

KAMESH PATEL 4
ROLL NO: 90

<tr>
</tr>

<tr>
</tr>

<tr>
<td rowspan="2">11:40 to 12:40</td>
<td rowspan="2">SE</td>
<td rowspan="2">ITA</td>
<td rowspan="2">SE</td>
<td rowspan="2">SE</td>
</tr>

<tr>
</tr>

<tr>
<td colspan="1">12:40 to 1:05</td>
<td colspan="5" style="background-color:yellow">Lunch Break</td>
</tr>

<tr>
<td rowspan="2">1:05 to 2:05</td>
<td rowspan="2">ITM</td>
<td rowspan="2">ITA</td>
<td rowspan="3">B1:ITA<br />B2:PRJ<br />B3:PRJ<br />B4:SE<br />B5:ITA</td>
<td rowspan="3">B1:PRJ<br />B2:ITA<br />B3:ITA<br />B4:PRJ<br />B5:ITA</td>
<td rowspan="3">B1:ITA<br />B2:ITA<br />B3:SE<br />B4:PRJ<br />B5:SE</td>
</tr>

<tr>
</tr>

<tr>
<td rowspan="2">2:05 to 3:05</td>
<td rowspan="2">ISA</td>
<td rowspan="2">AOS</td>
</tr>

<tr>
</tr>

<tr>
<td colspan="1">3:05 to 3:15</td>
<td colspan="5" style="background-color:yellow">Tea Break</td>
</tr>

KAMESH PATEL 5
ROLL NO: 90

<tr>
<td rowspan="2">3:15 to 4:15</td>
<td rowspan="3">B1:SE<br />B2:ITA<br />B3:PRJ<br />B4:ITA<br />B5:PRJ</td>
<td rowspan="2">ITA</td>
<td rowspan="2">ISA</td>
<td rowspan="2">ISA</td>
<td rowspan="3">B1:PRJ<br />B2:PRJ<br />B3:PRJ<br />B4:PRJ<br />B5:PRJ</td>
</tr>

<tr>
</tr>

<tr>
<td rowspan="2">4:15 to 5:15</td>
<td rowspan="2">SE</td>
<td rowspan="2">AOS</td>
<td rowspan="2">ITM</td>
</tr>

</table>
</center>
<br /><br />
<a href="index.html">Back to Index</a>
</body>
</html>

KAMESH PATEL 6
ROLL NO: 90

OUTPUT :

KAMESH PATEL 7
ROLL NO: 90

PRACTICAL – 3

AIM : Write a program to create Home-Page using FRAMSET.

Program :

p3.html Page

<html>
<head>
<title>Third Practical</title>
</head>

<frameset rows="20%,60%,10%">
<frameset cols="10%,*">
<frame name="header_logo" src="IMG_LOGO.jpg" />
<frame name="header_title" src="p3(1).html" />
</frameset>
<frameset cols="15%,*">
<frame name="link" src="p3(2).html" />
<frame name="main" src="" />
</frameset>
<frame name="footer" src="p3(3).html" />
</frameset>

</html>

p3(1).html Page

<html>
<body>

<center>
<h5>Shree Navsari Paschim Vibhag Koli Samaj Kalyankari Trust Sanchalit</h5>
<h2>Mahatma Gandhi Institute of Technical Education & Research Center, Navsari</h2>
</center>

</body>
</html>

KAMESH PATEL 8
ROLL NO: 90

p3(2).html Page

<html>
<head>
<style type="text/css">
a
{
text-decoration:none;
color:gray;
}
a:hover
{
text-decoration:underline;
color:silver;
}
li
{
list-style-type:none;
}
</style>
</head>
<body>
<br /><br />
<div style="background-color:#f1f2f3; -moz-border-radius:1em">
<br />
<ul>
<li><a href="p1.html" target="main" title="1st prac">First Practical</a></li>
<br />
<li><a href="p2.html" target="main" title="2nd prac">Second Practical</a></li>
</ul>
<br />
</div>
</body>
</html>

p3(3).html Page

<html>
<body>
<center>
<h5>&#169 by Rakesh Kumar</h5>
</center>
</body>
</html>

KAMESH PATEL 9
ROLL NO: 90

OUTPUT :

p3.html output :

KAMESH PATEL 10
ROLL NO: 90

PRACTICAL – 4
AIM : Write a program to create a simple form that will show all the INPUT METHODS available in
HTML.

Program :

<html>
<head>
<title> Forth Practical </title>
<style type="text/css">
body
{
background-color: silver;
}
.main
{
margin-top:100px;
text-align:center;
}
a
{
color:#000000;
text-decoration:none;
}
a:hover
{
color:#FFFFFF;
text-decoration:none;
}
</style>
<body>
<center>
<table class="main">
<tr>
<th colspan="2" style="text-align: center; font-weight: bold; height: 40px">HTML Form</th>
</tr>

<tr>
<td style="text-align:right; height:40px">Enter Your name : </td>
<td style="text-align:left"><input type="text" id="txtName" value="" /></td>
</tr>

<tr>
<td style="text-align:right; height:40px">Address : </td>

KAMESH PATEL 11
ROLL NO: 90

<td style="text-align:left"><textarea id="txtAddress"></textarea></td>


</tr>

<tr>
<td style="text-align:right; height:40px">Enter your Email : </td>
<td style="text-align:left"><input type="text" id="txtEmail" /></td>
</tr>

<tr>
<td style="text-align:right; height:40px">Mobile no. : </td>
<td style="text-align:left"><input type="text" id="txtMobno" value="" /></td>
</tr>

<tr>
<td style="text-align:right; height:40px">Gender : </td>
<td style="text-align:left"><input type="radio" name="radio">Male</input>
<input type="radio" name="radio">Female</input></td>
</tr>

<tr>
<td style="text-align:right; height:40px">Enter your Password : </td>
<td style="text-align:left"><input type="password" id="txtPass" value="" /></td>
</tr>

<tr>
<td style="text-align:right; height:40px">Re-enter Password : </td>
<td style="text-align:left"><input type="password" id="txtcPass" value="" /></td>
</tr>

<tr>
<td style="text-align:right; height:40px">Country : </td>
<td style="text-align:left">
<select name="listbox" style="height:22px;width:235px;">
<option value="- Select One -">- Select One -</option>
<option value="Australia">Australia</option>
<option value="Brazil">Brazil</option>
<option value="Canada">Canada</option>
<option value="China">China</option>
<option value="Egypt">Egypt</option>
<option value="India">India</option>
<option value="Pakistan">Pakistan</option>
<option value="Saudi Arabia">Saudi Arabia</option>
<option value="South Africa">South Africa</option>
<option value="Sri Lanka">Sri Lanka</option>
<option value="United Arab Emirates">United Arab Emirates</option>
<option value="United States">United States</option>
<option value="Zimbabwe">Zimbabwe</option>

KAMESH PATEL 12
ROLL NO: 90

</select>

</td>
</tr>

<tr>
<td colspan="2" style="height:40px"><input type="button" value="Submit" /></td>
</tr>

</table>
</center>
<br /><br />
<a href="index.html">Back to Index</a>
</body>
</html>

OUTPUT :

KAMESH PATEL 13
ROLL NO: 90

PRACTICAL – 5

AIM : Write a program which validate the user INPUT through the form on client side only. Form
has your biodata field Script should display appropriate message box after validation from the INPUT.

Program :

<html>
<head>
<title>Javascript Practical</title>
<style type="text/css">
body
{
background-color: silver;
}
.main
{
margin-top:100px;
text-align:center;
}
a
{
color:#000000;
text-decoration:none;
}
a:hover
{
color:#FFFFFF;
text-decoration:none;
}
</style>
<script type="text/javascript">

var at="@";
var dot=".";

function valid()
{
if(document.getElementById("txtName").value=="")
{

KAMESH PATEL 14
ROLL NO: 90

alert("Please Enter your name.");


}
if(document.getElementById("txtEmail").value=="")
{
alert("Enetr your email.");
}
else
{
if(document.getElementById("txtEmail").value.indexOf(at)=="-1")
{
if(document.getElementById("txtEmail").value.indexOf(dot)=="-1")
{
alert("Please Enter valid email.");
}
}
}

if(document.getElementById("txtAddress").value=="")
{
alert("Please Enter your address.");
}

if(document.getElementById("txtMobno").value=="")
{
alert("Please Enter your Mobile no.");
}
if(document.getElementById("txtPass").value != document.getElementById("txtcPass").value)
{
alert("Password is not match.");
}

}
</script>
<body>
<center>
<table class="main">
<tr>
<th colspan="2" style="text-align: center; font-weight: bold; height: 40px">Javascript
Validation Form</th>
</tr>

<tr>
<td style="text-align:right; height:40px">Enter Your name : </td>
<td style="text-align:left"><input type="text" id="txtName" value="" /></td>
</tr>

<tr>

KAMESH PATEL 15
ROLL NO: 90

<td style="text-align:right; height:40px">Address : </td>


<td style="text-align:left"><textarea id="txtAddress"></textarea></td>
</tr>

<tr>
<td style="text-align:right; height:40px">Enter your Email : </td>
<td style="text-align:left"><input type="text" id="txtEmail" /></td>
</tr>

<tr>
<td style="text-align:right; height:40px">Mobile no. : </td>
<td style="text-align:left"><input type="text" id="txtMobno" value="" /></td>
</tr>

<tr>
<td style="text-align:right; height:40px">Enter your Password : </td>
<td style="text-align:left"><input type="password" id="txtPass" value="" /></td>
</tr>

<tr>
<td style="text-align:right; height:40px">Re-enter Password : </td>
<td style="text-align:left"><input type="password" id="txtcPass" value="" /></td>
</tr>

<tr>
<td colspan="2" style="height:40px"><input type="button" value="Submit"
onClick="valid()" /></td>
</tr>

</table>
</center>
<br /><br />
<a href="index.html">Back to Index</a>
</body>
</html>

KAMESH PATEL 16
ROLL NO: 90

OUTPUT :

KAMESH PATEL 17
ROLL NO: 90

PRACTICAL – 6

AIM : Write a java script to open a new window and display the text of parent window.
Also display history.

Program :

<head>

<title>Untitled Document</title>

<script language="javascript">

function nextpage()

alert(window.location.href);

window.location.href="bgcolor.html";

function histryprev()

window.history.back();

function histryfor()

window.history.forward();

</script>

KAMESH PATEL 18
ROLL NO: 90

</head>

<body>

<input type="button" value="next" onclick="nextpage()" />

<input type="button" value="pre" onclick="histryprev()"/>

<input type="button" value="forward" onclick="histryfor()" />

</body>

</html>

KAMESH PATEL 19
ROLL NO: 90

PRACTICAL - 7

AIM : Create a webpage that does the animation of images. Initially it displays 3 images.
After every one second images should change their order of display. Means image 1
should go in place of 2, image 2 in place of 3 and 3 in place of 1 and so on.

Program :
<head>

<title>Untitled Document</title>

<script language="javascript">

images = new Array()

images[0]="Hydrangeas.jpg";

images[1]="Chrysanthemum.jpg";

images[2]="Desert.jpg";

setTimeout("alterimage()",3000);

x=0;

function alterimage()

document.getElementById("imgAlter").src=images[x];

if(x >= (images.length-1))

x=0;

else

KAMESH PATEL 20
ROLL NO: 90

x=x+1;

setTimeout("alterimage()",3000);

function changeImage()

document.getElementById("imgsetimage").src="Desert.jpg";

function setimage()

document.getElementById("imgsetimage").src="Chrysanthemum.jpg";

</script>

</head>

<body>

<img src="" width="400" height="400" id="imgAlter" />

<img id="imgsetimage" src="Chrysanthemum.jpg" width="300" height="300" />

</body>

</html>

KAMESH PATEL 21
ROLL NO: 90

PRACTICAL - 8

AIM : Write a java script code of displaying scrolling message in a status bar of a
window.

Program :

<head>

<title>Untitled Document</title>

<script language="javascript">

document.write(document.fileCreatedDate);

msg=" hello world";

i=0;

images=new Array();

function alternateimage()

function scrollmsg()

//alert(msg.length);

frontpart=msg.substring(i,msg.length);

backpart=msg.substring(0,i);

KAMESH PATEL 22
ROLL NO: 90

//alert(frontpart);

window.status=frontpart + backpart;

if(i >= 0)

i++;

if(i == msg.length)

i=0;

setTimeout("scrollmsg()",300);

</script>

</head> <body>

onload="scrollmsg()"

</body>

</html>

KAMESH PATEL 23
ROLL NO: 90

PRACTICAL – 9
AIM : Write a program to apply css to your registeration form.

Program :
<html>
<head>
<style>
.class
{
text-align:center;
font-size:20px;
color:#FF0000;
font-family:"chiller";
}
.class1
{
font-family:"chiller";
}
</style>
</head>
<body>
<center>
<font style="color:#0000CC" size="+3">
<marquee> REGISTRATION FORM </marquee>
</font>
</center>
<U>
FILL ALL DATA BELLOW
</U>
<form >
<table class="class">
<tr ALIGN="left"><th>First Name </th><th> <input type="text" id="txtFname"
class="class"/></th></tr>
<tr ALIGN="left" ><th>Last Name</th><th> <input type="text" id="txtLname"
class="class"/> </th></tr>
<tr ALIGN="left"><th>Address:</th><th><input type="text" id="txtAdd"
class="class"/></th></tr>

KAMESH PATEL 24
ROLL NO: 90

<tr ALIGN="left"><th>Password: </th><th> <input type="password" id="txtpass"


class="class"/> </th></tr>
<tr ALIGN="left"><th>Conform Password: </th><th> <input type="password"
id="txtcpass" class="class"/> </th></tr>
<tr ALIGN="left"><th>Gender: </th><th><input type="radio" name="a"
value="MALE"/>MALE<input type="radio" name="a" value="FEMALE"/>
FEMALE</th></tr>
<tr ><th align="right"><input type="submit" value="submit"/></th></tr>
</form>
</table>
</body>
</html>

KAMESH PATEL 25
ROLL NO: 90

PRACTICAL - 10
AIM: Write an html page which inputs the below mentioned fields and invokes the java servlet
programs which enters the fields in the database table. Fields: roll no, name, department, email.

Index.jsp
<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>insert.jsp</title>

</head>

<body>

<form action="insert_data" method="post">

<center>

<table>

<tr> <th> Roll_no: </th>

<th> <input type="text" name="rn"> </th>

</tr>

<tr> <th> Name: </th>

<th> <input type="text" name="nm"> </th>

</tr>

<tr> <th> Email Id: </th>

<th> <input type="text" name="eml"> </th>

</tr>

<tr> <th> Department: </th>

<th> <input type="text" name="dpt"> </th>

</tr>

KAMESH PATEL 26
ROLL NO: 90

<tr>

<th colspan="2">

<input type="submit" name="submit" value="SUBMIT">

</th>

</tr>

</table>

</center>

</form>

</body>

</html>

Insert_data.java
import java.awt.GridBagConstraints;

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;

import javax.servlet.http.*;

import java.sql.*;

public class insert_data extends HttpServlet {

KAMESH PATEL 27
ROLL NO: 90

protected void processRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

try {

Connection con = DriverManager.getConnection("jdbc:odbc:mngDB","","");

Statement s = con.createStatement();

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

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

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

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

s.executeUpdate("insert into mngtbl values('"+ rn + "','"+nm +"','"+eml +"','"+dpt +"')");

s.close();

con.close();

catch(Exception e)

out.println(e);

finally

out.close();

KAMESH PATEL 28
ROLL NO: 90

KAMESH PATEL 29
ROLL NO: 90

PRACTICAL-11
AIM: Write one HTML page that will ask to user for login when user submit this HTML, run servlet
on the server, which will make query in the database to check whether username and password are
correct or not. If user is valid create one session for this user and put one link in servlet1, that if click
will execute servlet2 on server. In servlet2, print what is the content of session that was established in
servlet1.

Index.jsp
<html>

<body>

<form action="welcome" method="post" >

<center>

<table>

<tr> <th> USER ID: </th>

<th> <input type="text" name="user"> </th> </tr>

<tr> <th> PASSWORD: </th>

<th> <input type="password" name="pass"> </th> </tr>

<tr> <th colspan="2">

<input type="submit" name="submit" value="LOGIN" onclick="valid()">

</th>

</tr>

</table>

</center>

</form>

</body>

KAMESH PATEL 30
ROLL NO: 90

</html>

welcome.java

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;

import javax.servlet.http.*;

import java.sql.*;

public class welcome extends HttpServlet

protected void processRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

try {

Connection con =DriverManager.getConnection("jdbc:odbc:lgnDB","","");

String u = request.getParameter("user");

String p = request.getParameter("pass");

Statement s = con.createStatement();

KAMESH PATEL 31
ROLL NO: 90

ResultSet rs= s.executeQuery("select * from login where username ='"+ u +"' and
password = '"+ p +"'");

if(rs.next())

HttpSession ses = request.getSession(true);

ses.setAttribute("username",u);

ses.setAttribute("status","login");

response.sendRedirect("hello");

else

response.sendRedirect("index");

catch(Exception e)

out.println(e);

finally {

out.close();

KAMESH PATEL 32
ROLL NO: 90

Hello.java

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;

import javax.servlet.http.*;

import java.sql.*;

import java.util.Enumeration;

import java.io.*;

import java.text.*;

import java.util.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class hello extends HttpServlet

protected void processRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

KAMESH PATEL 33
ROLL NO: 90

try {

HttpSession ses = request.getSession();

out.print(("Welcoem----"));

out.print(ses.getAttribute("username") + "</br>");

out.print(ses.getId()+"</br>");

catch(Exception e)

out.print(e);

finally {

out.close();

KAMESH PATEL 34
ROLL NO: 90

OUTPUT

KAMESH PATEL 35
ROLL NO: 90

PRACTICAL-12
AIM: Design a javaservlet to submit an html form and display the user’s choice in a browser. Form
contains: applicant’s name, age, expected salary, qualification.

Search.java
import java.io.IOException;

import java.io.PrintWriter;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.*;

public class search extends HttpServlet

protected void processRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

PrintWriter out = response.getWriter();

try { }

finally { out.close();

KAMESH PATEL 36
ROLL NO: 90

} }

@Override

protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

out.println("<html>");

out.println("<body>"

+"<center>"

+ "<form action=\"search\" method=\"post\">"

+"<table>"

+"<tr>"

+"<th>"

+"Name:"

+ "</th>"

+ "<th>"

+ "<input type=\"text\" name=\"name\">"

+"</th>"

+"</tr>"

+"<tr>"

+"<th>"

+"age:"

KAMESH PATEL 37
ROLL NO: 90

+ "</th>"

+ "<th>"

+ "<input type=\"text\" name=\"age\">"

+"</th>"

+"</tr>"

+"<tr>"

+"<th>"

+" Expected salary:"

+ "</th>"

+ "<th>"

+ "<input type=\"text\" name=\"slry\">"

+"</th>"

+"</tr>"

+"<tr>"

+"<th>"

+"qualification:"

+ "</th>"

+ "<th>"

+ "<input type=\"text\" name=\"qua\">"

+"</th>"

+"</tr>"

+"<tr>"

+ "<th colspan=\"2\">"

+ "<input type=\"submit\" name=\"submit\" value=\"ok\">"

+"</th>"

KAMESH PATEL 38
ROLL NO: 90

+"</tr>"

+"</table>"

+ "</form>"

+"</center>");

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

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

@Override

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException

PrintWriter out = response.getWriter();

try

Connection con = DriverManager.getConnection("jdbc:odbc:search","","");

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

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

String sal=request.getParameter("slry");

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

out.print(nm+"--"+age+"--"+sal+"---"+qua);

catch(Exception e)

out.print(e.toString());

KAMESH PATEL 39
ROLL NO: 90

Output:

KAMESH PATEL 40
ROLL NO: 90

PRACTICAL-13
AIM: Write a servlet that takes first name and last name from the user and generates login id such that
two characters are from the first name and four characters are from last name. Display the generated
login id.

Secreted.java
import java.io.IOException;

import java.io.PrintWriter;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.*;

public class search extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

PrintWriter out = response.getWriter();

try { }

finally { out.close(); }

KAMESH PATEL 41
ROLL NO: 90

@Override

protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

out.println("<html>");

out.println("<body>"

+"<center>"

+ "<form action=\"search\" method=\"post\">"

+"<table>"

+"<tr>" +"<th>" +"First name::" + "</th>"

+ "<th>" + "<input type=\"text\" name=\"name\">" </th>"

+"</tr>"

+"<tr>" +"<th>" +"Lastname:" + "</th>"

+ "<th>" + "<input type=\"text\" name=\"age\">" +"</th>"

+"</tr>"

+ "<th colspan=\"2\">"

+ "<input type=\"submit\" name=\"submit\" value=\"ok\">"

+"</th>" +"</tr>"

+"</table>"

+ "</form>"

+"</center>");

KAMESH PATEL 42
ROLL NO: 90

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

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

@Override

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException

//processRequest(request, response);

PrintWriter out = response.getWriter();

try

Connection con = riverManager.getConnection("jdbc:odbc:search","","");

int i;

String id,id1,id2;

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

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

id1 = (String) (nm.subSequence(0,2));

i=age.length();

id2 = age.substring(i-2, i);

id=id1+id2;

out.print("YOUR SECRET ID IS--"+id);

catch(Exception e)

{ out.print(e.toString());

} } }

KAMESH PATEL 43
ROLL NO: 90

OUTPUT:

KAMESH PATEL 44
ROLL NO: 90

PRACTICAL-14
AIM: Develop an application of online library through which user can make search of a book by
different category like author name, publication, ISBN, keyword in book title etc. Make suitable
assumption in design with brief description. Develop using Servlet.

Search.java
import java.io.IOException;

import java.io.PrintWriter;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.*;

public class search extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

PrintWriter out = response.getWriter();

try { }

} finally { out.close(); }

KAMESH PATEL 45
ROLL NO: 90

@Override

protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

out.println("<html>");

out.println("<body>"

+"<center>"

+ "<form action=\"search\" method=\"post\">"

+"<table>"

+"<tr>" +"<th>" +"First name::" + "</th>"

+ "<th>" + "<input type=\"text\" name=\"name\">" +"</th>"

+"</tr>"

+ "<th colspan=\"2\">"

+ "<input type=\"submit\" name=\"submit\" value=\"search\">"

+"</th>"+"</tr>"

+"</table>"

+ "</form>"

+"</center>");

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

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

KAMESH PATEL 46
ROLL NO: 90

@Override

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException

//processRequest(request, response);

PrintWriter out = response.getWriter();

try

Connection con = DriverManager.getConnection("jdbc:odbc:labry","","");

Statement s = con.createStatement();

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

ResultSet rs =s.executeQuery("select * from lab where name like '"+ nm+"' or pub like
'"+nm+"'or isdn like '"+ nm+"'or bookname like '"+nm+"'");

while(rs.next())

out.println(rs.getString("name")+"--"+rs.getString("pub")+"---rs.getString("isdn")+"---
"+rs.getString("bookname"));

catch(Exception e)

out.print(e.toString());

KAMESH PATEL 47
ROLL NO: 90

OUTPUT:

KAMESH PATEL 48
ROLL NO: 90

PRACTICAL - 15
AIM: Write an html page which inputs the below mentioned fields and invokes the JSP programs
which enters the fields in the database table. Fields: roll no, name, department, email.

Insert.html
<html>

<head>

<title></title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>

<body>

<form action="insertvalue.jsp" method="post">

<center>

<table>

<tr>

<th> Roll_no: </th>

<th> <input type="text" name="rn"> </th>

</tr>

<tr>

<th> Name: </th>

<th> <input type="text" name="nm"> </th>

</tr>

<tr> <th> Email Id: </th>

<th> <input type="text" name="eml"> </th>

KAMESH PATEL 49
ROLL NO: 90

</tr>

<tr> <th> Department: </th>

<th> <input type="text" name="dpt"> </th>

</tr>

<tr> <th colspan="2"> <input type="submit" name="submit" value="SUBMIT">

</th> </tr>

</table>

</center>

</form>

</body>

</html>

insertvalue.jsp
<%--

Document : insertvalue

Created on : Apr 2, 2011, 9:07:25 AM

Author : jenit

--%>

<%@page import="org.springframework.context.annotation.Import"%>

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<%@page import=" java.awt.GridBagConstraints"%>

<%@page import=" java.io.IOException"%>

<%@page import="java.io.PrintWriter"%>

KAMESH PATEL 50
ROLL NO: 90

<%@page import=" javax.servlet.ServletException"%>

<%@page import ="javax.servlet.http.HttpServlet"%>

<%@page import ="javax.servlet.http.HttpServletRequest"%>

<%@page import=" javax.servlet.http.HttpServletResponse"%>

<%@page import ="javax.servlet.http.*"%>

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

<html>

<body>

<%

Connection con = DriverManager.getConnection("jdbc:odbc:insert","","");

Statement s =con.createStatement();

String roll =(String) request.getParameter("rn");

String name1 = request.getParameter("nm");

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

String dept = request.getParameter("dpt");

s.executeUpdate("insert into std values('" + roll +"','"+ name1+"','"+ email +"','"+ dept+"')");

out.print("ONE ROW ADDED TO DATBASE THROUGH JSP PAGE");

s.close();

con.close();

%>

</body>

</html>

KAMESH PATEL 51
ROLL NO: 90

OUTPUT:

KAMESH PATEL 52
ROLL NO: 90

PRACTICAL - 16

AIM: Write one HTML page that will ask to user for login when user submit this HTML, run JSP on
the server, which will make query in the database to check whether username and password are correct
or not. If user is valid create one session for this user and put one link in JSP1, that if click will execute
JSP2 on server. In JSP2, print what is the content of session that was established in JSP1.

Login.html
<html>

<body>

<form action="welcome" method="post" >

<center>

<table>

<tr> <th> USER ID: </th>

<th> <input type="text" name="user"> </th> </tr>

<tr> <th> PASSWORD: </th>

<th> <input type="password" name="pass"> </th> </tr>

<tr> <th colspan="2">

<input type="submit" name="submit" value="LOGIN" onclick="valid()">

</th>

</tr>

</table>

</center>

</form>

</body>

</html>

KAMESH PATEL 53
ROLL NO: 90

welcome.jsp

<% page import=” java.io.IOException” %>

<% page import=” java.io.PrintWriter” %>

<% page import=” javax.servlet.ServletException” %>

<% page import =” javax.servlet.http.HttpServlet” %>

<% page import=” javax.servlet.http.HttpServletRequest” %>

<% page import=” javax.servlet.http.HttpServletResponse” %>

<% page import=” javax.servlet.http.* ” %>

<% page import =” java.sql.* ” %>

<html>

<body>

<%

Connection con =DriverManager.getConnection("jdbc:odbc:lgnDB","","");

String u = request.getParameter("user");

String p = request.getParameter("pass");

Statement s = con.createStatement();

ResultSet rs= s.executeQuery("select * from login where username ='"+ u +"' and
password = '"+ p +"'");

if(rs.next())

HttpSession ses = request.getSession(true);

ses.setAttribute("username",u);

KAMESH PATEL 54
ROLL NO: 90

ses.setAttribute("status","login");

response.sendRedirect("hello");

else

response.sendRedirect("index");

catch(Exception e)

out.println(e);

finally {

out.close();

%>

</body>

</html>

KAMESH PATEL 55
ROLL NO: 90

Hello.jsp

<% page import=” java.io.IOException”%>

<% page import =”java.io.PrintWriter”%>

<% page import=” javax.servlet.ServletException”%>

<% page import=” java.sql.* ”%>

<% page import=” java.util.Enumeration”%>

<% page import=” java.io.* ”%>

<% page import=” java.text.* ”%>

<% page import=” java.util.* ”%>

<% page import=” javax.servlet.* ”%>

<% page import=” javax.servlet.http.* ”%>

<html>

<body>

<% HttpSession ses = request.getSession();

out.print(("Welcoem----"));

out.print(ses.getAttribute("username") + "</br>");

out.print(ses.getId()+"</br>");

catch(Exception e)

{ out.print(e); }%>
</body>

</html>

KAMESH PATEL 56
ROLL NO: 90

OUTPUT:

KAMESH PATEL 57
ROLL NO: 90

PRACTICAL - 17
AIM: Design a JSP to submit an html form and display the user’s choice in a browser. Form contains:
applicant’s name, age, expected salary, qualification.

Submit.jsp
<%--

Document : submit

Created on : Apr 4, 2011, 12:32:19 AM

Author : jenit

--%>

<%@page import="java.sql.DriverManager"%>

<%@page import="java.sql.Connection"%>

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<title></title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>

<body>

<center>

<table>

KAMESH PATEL 58
ROLL NO: 90

<form action="" method="post">

<tr>

<th align="left">

Name:

</th>

<th>

<input type="text" name="nm">

</th>

</tr><tr>

<th align="left">

Age:

</th>

<th align="left">

<input type="text" name="age">

</th>

</tr>

<tr>

<th align="left">

salary:

</th>

<th align="left">

<input type="text" name="slry">

</th >

</tr>

<tr>

KAMESH PATEL 59
ROLL NO: 90

<th align="left">

Qualification:

</th>

<th align="left">

<input type="text" name="qua">

</th>

</tr>

<tr>

<th colspan="2">

<input type="submit" name="sb" value="sub">

</th>

</tr>

</form>

</table>

</center>

<%

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

String a = request.getParameter("age");

String s = request.getParameter("slry");

String q = request.getParameter("qua");

out.print(nm +"----"+ a+"-----"+s+"-----"+q);

%>

</body>

KAMESH PATEL 60
ROLL NO: 90

</html>

OUTPUT:

KAMESH PATEL 61
ROLL NO: 90

PRACTICAL - 18
AIM: Write a JSP that takes first name and last name from the user and generates login id such that
two characters are from the first name and four characters are from last name. Display the generated
login id.

Createid.jsp
<%--

Document : id

Created on : Apr 4, 2011, 1:19:48 AM

Author : jenit

--%>

<%@page import="com.sun.corba.se.impl.protocol.giopmsgheaders.Message"%>

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

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>JSP Page</title>

</head>

<body>

<center>

<table>

<form action="" method="post">

<tr>

<th align="left"> Frist Name: </th>

<th> <input type="text" name="nm"> </th> </tr>

KAMESH PATEL 62
ROLL NO: 90

<tr>

<th align="left"> Last Name: </th>

<th align="left"> <input type="text" name="qua"> </th>

</tr>

<tr>

<th colspan="2"> <input type="submit" name="sb" value="sub"> </th>

</tr>

</form>

</table>

</center>

<%

try{

String id,id1,id2;

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

id1= nm.substring(0,2);

int i=(request.getParameter("qua")).length();

id2 = (request.getParameter("qua")).substring(i-2,i);

out.print(id1+id2);

catch(Exception e)

{ out.print(e);} %>

</body>

</html>

KAMESH PATEL 63
ROLL NO: 90

OUTPUT:

KAMESH PATEL 64
ROLL NO: 90

PRACTICAL - 19
AIM: Develop an application of online library through which user can make search of a book by
different category like author name, publication, ISBN, keyword in book title etc. Make suitable
assumption in design with brief description. Develop using JSP.

LIBRARY.JSP
<%--

Document : library

Created on : Apr 13, 2011, 1:36:51 PM

Author : jenit

--%>

<%@page import="java.sql.Statement"%>

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<%@page import=" java.awt.GridBagConstraints"%>

<%@page import=" java.io.IOException"%>

<%@page import="java.io.PrintWriter"%>

<%@page import=" javax.servlet.ServletException"%>

<%@page import ="javax.servlet.http.HttpServlet"%>

<%@page import ="javax.servlet.http.HttpServletRequest"%>

<%@page import=" javax.servlet.http.HttpServletResponse"%>

<%@page import ="javax.servlet.http.*"%>

<%@page import ="javax.servlet.*"%>

KAMESH PATEL 65
ROLL NO: 90

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

<%@page import="java.util.Enumeration"%>

<%@page import=" java.io.* "%>

<%@page import="java.text.*"%>

<%@page import=" java.util.* "%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Library</title>

</head>

<body>

<center>

<table>

<form action="" method="post">

<table>

<tr>

<th>

</th>

<th>

<input type="text" name="name">

</th>

<th>

<input type="submit" name="submit" value="search">

KAMESH PATEL 66
ROLL NO: 90

</th>

</tr>

</table>

</form>

</table>

</center>

<%

try

Connection con = DriverManager.getConnection("jdbc:odbc:labry","","");

Statement s = con.createStatement();

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

ResultSet rs =s.executeQuery("select * from lab where name like '"+ nm+"' or pub like
'"+nm+"'or isdn like '"+ nm+"'or bookname like '"+nm+"'");

while(rs.next())

out.println(rs.getString("name")+"--"+rs.getString("pub")+"---"+rs.getString("isdn")
+"---"+rs.getString("bookname"));

catch(Exception e)

out.print(e.toString());

KAMESH PATEL 67
ROLL NO: 90

</body>

</html>

OUTPUT:

KAMESH PATEL 68
ROLL NO: 90

PRACTICAL - 20
AIM: Write a code in JSP which inserts following data in database. Fields: lucky no, birthday, name.

Alldetail.jsp

<%@page import=" java.awt.GridBagConstraints"%>

<%@page import=" java.io.IOException"%>

<%@page import="java.io.PrintWriter"%>

<%@page import=" javax.servlet.ServletException"%>

<%@page import ="javax.servlet.http.HttpServlet"%>

<%@page import ="javax.servlet.http.HttpServletRequest"%>

<%@page import=" javax.servlet.http.HttpServletResponse"%>

<%@page import ="javax.servlet.http.*"%>

<%@page import ="javax.servlet.*"%>

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

<%@page import="java.util.Enumeration"%>

<%@page import=" java.io.* "%>

<%@page import="java.text.*"%>

<%@page import=" java.util.* "%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>JSP Page</title>

</head>

KAMESH PATEL 69
ROLL NO: 90

<body>

<center>

Enter Your Total Data Below

<form action="table.jsp" method="post">

<table>

<tr>

<th> Lucky_no: </th>

<th> <input type="text" name="no"></th>

</tr>

<tr>

<th> Your Name: </th>

<th> <input type="text" name="nm"> </th>

</tr>

<tr>

<th> BirthDate </th>

<th> <input type="text" name="dt"> </th>

</tr>

<tr>

<th colspan="2"> <input type="submit" value="Submit"> </th>

</tr>

</table>

</form>

</center>

KAMESH PATEL 70
ROLL NO: 90

<%

try

Connection con = DriverManager.getConnection("jdbc:odbc:detail","","");

Statement s = con.createStatement();

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

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

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

//out.println(no +"--"+nm+"--"+dt);

s.executeUpdate("insert into entry values('"+no+"','"+ nm +"','"+ dt +"')");

s.close();

con.close();

catch(Exception e)

out.println(e);

%>

</body>

</html>

OUTPUT:

KAMESH PATEL 71
ROLL NO: 90

KAMESH PATEL 72
ROLL NO: 90

PRACTICAL - 1

Aim: WAP. to implement Otion Explict (with & witout).

 (A)
<%@language="VBScript"%>
<%Option Explicit%>
<html>
<body bgcolor="#999999">
<%
dim name
name="kuntal"
response.write name
%>
</body>
</html>

 (B)
<%@language="VBScript"%>
<%Option Explicit%>
<HTML>
<BODY bgcolor=GRAY>
<b>
<%
dim mystring
mystrng="Hello"
response.write mystrng

KAMESH PATEL 73
ROLL NO: 90

%>
</b>
</BODY>
</HTML>

KAMESH PATEL 74
ROLL NO: 90

PRACTICAL - 2

Aim:- WAP. to implement find min & max using If in ASP.


<html>
<body>
<%@language="VBScript"%>
<%
dim a
dim b
a=10
b=5
If a<b then
{
response.write("b is max")
}
Else
{
response.write("a is max")
}
End If
%>
</body>
</html>

KAMESH PATEL 75
ROLL NO: 90

PRACTICAL – 3
Aim:- WAP. To showing Buffer property – Flush ,Clear ,End,method of Response Object.

<%@language="VBScript"%>
<%Option Explicit%>
<%Response.Buffer = true%>
<HTML>
<BODY>
Lets send some text to HTML output stream.<p>
It is waiting to be send - Lets send it.
<%
Response.Flush
%>
<%
Response.Write "We can control the output of response.write method too"
Response.Clear
%>
<p>Now finish - Lets end it.
<%
Response.End
%>
Wait a minute - I want to say this,it is too late!
</BODY>
</HTML>

KAMESH PATEL 76
ROLL NO: 90

KAMESH PATEL 77
ROLL NO: 90

PRACTICAL - 4

Aim:- WAP. to implement printing all servervariables.

 (A)
<%@language="VBScript"%>
<% option explicit %>
<PRE>
<%= Request.ServerVariables("ALL_HTTP")%>
</PRE>

 (B)

<%@language="VBScript"%>
<% option explicit %>
<PRE>
<%= Request.ServerVariables("ALL_RAW")%>
</PRE>

KAMESH PATEL 78
ROLL NO: 90

PRACTICAL - 5

Aim:- WAP. to implement showing use of QueryString (with URL ,with <a herf….>)
<%@language="VBScript"%>
<% option explicit %>

<A href="pra5.asp?name=Hi">Normal</A> <BR>


<A href="pra5.asp?code=1&amp;name=Hello+how+are+u?">Multiple</A> <BR>
<A href="pra5.asp">Null</A> <BR>
<%
Dim var
For Each var in Request.Querystring
Response.Write var & " : " & Request.Querystring(var) & "<BR>"
Next
%>

KAMESH PATEL 79
ROLL NO: 90

KAMESH PATEL 80
ROLL NO: 90

PRACTICAL - 6

Aim:- WAP. to implement generating QueryString using Get Method .(Form method)
<HTML>
<HEAD>
<TITLE>REG</TITLE>
</HEAD>
<BODY>
<FORM name="f1" method="post" action="../../../Users/MGITER/Pictures/ASP/p18a.asp">
<TABLE>
<TR>
<TD width=20%>Name :</TD>
<TD width=20%><input type="text" name="txtname"></TD>
<TD width=20%>&nbsp;</TD>
<TD width=20%>&nbsp;</TD>
</TR>
<TR>
<TD>Birthdate :</TD>
<TD><input type="text" name="txtdob"></TD>
<TD>&nbsp;</TD>
<TD>&nbsp;</TD>
</TR>
<TR>
<TD>Age :</TD>
<TD><input type="text" name="txtage"></TD>
<TD>&nbsp;</TD>
<TD>&nbsp;</TD>

KAMESH PATEL 81
ROLL NO: 90

</TR>
<TR>
<TD>Sex :</TD>
<TD><input type="radio" name="rdsex" value="m">Male</TD>
<TD><input type="radio" name="rdsex" value="f">Female</TD>
<TD></TD>
</TR>
<TR>
<TD>Languages :</TD>
<TD><input type="checkbox" name="h">Hindi</TD>
<TD><input type="checkbox" name="g">Gujrati</TD>
<TD><input type="checkbox" name="e">English</TD>
</TR>
<TR>
<TD>&nbsp;</TD>
<TD><input type="submit" name="submit" value="Submit"></TD>
<TD>&nbsp;</TD>
<TD>&nbsp;</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>

KAMESH PATEL 82
ROLL NO: 90

KAMESH PATEL 83
ROLL NO: 90

PRACTICAL - 7

Aim:- WAP. to implement Cookies &Reading Cookies and also shown Session.
<%@language="VBScript"%>
<% option explicit %>
<HTML>
<BODY>
<FORM name="f1" method="post" action="pra7a.asp">
<TABLE>
<TR>
<TD>User ID :</TD>
<TD><INPUT TYPE="text" NAME="txtuser" VALUE="<%=
Request.Cookies("userinfo")("user")%>"></TD>
<TD>&nbsp;</TD>
</TR>
<TR>
<TD>Password : </TD>
<TD><INPUT TYPE="password" NAME="txtpass" VALUE="<%=
Request.Cookies("userinfo")("pass")%>"></TD>
<TD>&nbsp;</TD>
</TR>
<TR>
<TD>&nbsp;</TD>
<TD>&nbsp;</TD>
<TD><INPUT TYPE="submit" NAME="submit" VALUE="SUBMIT"></TD>
<TR>
<TR>
<TD>&nbsp;</TD>

KAMESH PATEL 84
ROLL NO: 90

<TD>&nbsp;</TD>
<TD><INPUT TYPE="checkbox" NAME="chk1">Remember me on this
computer</TD>
<TR>
</TABLE>
</FORM>
</BODY>
</HTML>

KAMESH PATEL 85
ROLL NO: 90

KAMESH PATEL 86
ROLL NO: 90

PRACTICAL - 1
AIM : Write a PHP script having username and age field. Using GET/ POST method redirect the user
to another page and print username and age on another page.

Program :

get1.php

<html>
<head>
<title>Get Method</title>
</head>

<body>
<form action="get2.php" method="get">
<table>
<tr>
<td>Enter your name : </td>
<td><input type="text" name="uname" /></td>
</tr>
<tr>
<td>Enter your Age : </td>
<td><input type="text" name="age" /></td>
</tr>
<tr>
<td colspan="2" style="text-align:center"><input type="submit" name="submit"
value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>

get2.php

<html>
<head>
<title>Get Method</title>
</head>

KAMESH PATEL 87
ROLL NO: 90

<body>

<?php

echo "Welcome, ".$_GET["uname"]."."."<br />";


echo "Your age is ".$_GET["age"];
?>

</body>
</html>

post1.php

<html>
<head>
<title>Post Method</title>
</head>

<body>
<form action="post2.php" method="post">
<table>
<tr>
<td>Enter your name : </td>
<td><input type="text" name="uname" /></td>
</tr>
<tr>
<td>Enter your Age : </td>
<td><input type="text" name="age" /></td>
</tr>
<tr>
<td colspan="2" style="text-align:center"><input type="submit" name="submit"
value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>

post2.php

<html>
<head>

KAMESH PATEL 88
ROLL NO: 90

<title>Post Method</title>
</head>

<body>

<?php

echo "Welcome, ".$_POST["uname"]."."."<br />";


echo "Your age is ".$_POST["age"];

?>
</body>
</html>

OUTPUT :

get1.php output :

KAMESH PATEL 89
ROLL NO: 90

get2.php output :

post1.php output :

post2.php output :

KAMESH PATEL 90
ROLL NO: 90

KAMESH PATEL 91
ROLL NO: 90

PRACTICAL-2
AIM: Write PHP Script to set Cookie on one page. Retrieve that cookies on to another page and
display them if they are available.

Program :

Cookie.php

<html>
<head>
<title>Cookie</title>
</head>
<body style=”background-color:silver”>

<?php
setcookie("user","Amin Jariwala",time()+360) // It create cookie n pass value of user
?>

</body>
</html>

Welcome.php

<html>
<head>
<title>Cookie</title>
</head>

<body style=”background-color:silver”>

<?php
if (isset($_COOKIE["user"]))
echo "Welcome " . $_COOKIE["user"] . "!<br />";
else
echo "Welcome guest!<br />";
?>

</body>
</html>

KAMESH PATEL 92
ROLL NO: 90

OUTPUT :

Cookie.php output :

KAMESH PATEL 93
ROLL NO: 90

Practical-3
AIM: Write PHP Script to maintain hit counter for web pages using Session variable.

Program :

Session.php

<html>
<head>
<title>Session</title>
</head>

<body style="background-color:silver">

<?php
session_start();

if(isset($_SESSION['count']))
{
$_SESSION['count']=$_SESSION['count']+1;
}
else
{
$_SESSION['count']=1;
}
echo "site visited-----".$_SESSION['count'];
?>

</body>
</html>

KAMESH PATEL 94
ROLL NO: 90

OUTPUT :

Session.php output :

KAMESH PATEL 95
ROLL NO: 90

 After ten time refreshing…

KAMESH PATEL 96
ROLL NO: 90

PRACTICAL-4

AIM: Write a script to upload a file. Upload those files only with extension “.jpg/.jpeg”.

Program :

Upload_form.php

<html>
<head>
<title>File Uploder</title>
</head>
<body style="background-color:silver">

<form enctype="multipart/form-data" action="uploader.php" method="POST">


<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

</body>
</html>

Uploder.php

<html>
<head>
<title>File Upload</title>
</head>
<body style="background-color:silver">

<?php

if (($_FILES["uploadedfile"]["type"] == "image/gif")
|| ($_FILES["uploadedfile"]["type"] == "image/jpeg")
|| ($_FILES["uploadedfile"]["type"] == "image/png" )
&& ($_FILES["uploadedfile"]["size"] < 10000))
{
move_uploaded_file($_FILES["uploadedfile"]["tmp_name"],
"C:/wamp/www/PHP/PHP3/Uploaded Files/" . $_FILES["uploadedfile"]["name"]);
echo "File succesfully upload.";

KAMESH PATEL 97
ROLL NO: 90

else
{
echo "Files must be either JPEG, GIF, or PNG and less than 10,000 kb";
}

?>

</body>
</html>

OUTPUT :

Upload_form.php output :

KAMESH PATEL 98
ROLL NO: 90

Uploader.php output :

KAMESH PATEL 99
ROLL NO: 90

PRACTICAL-5
AIM: Create Login page and ask user to enter Username and Password. Consult the Database for the
validity of the user and if user is valid then store this information in Session and redirect user to
Welcome page. Display Username and welcome message to that Welcome page, Otherwise display the
Login page again with appropriate error message.

Program :

Login_form.php

<html>
<head>
<title>Login Form</title>
</head>
<body style="background-color:silver">

<form action="login.php" method="post">


<table>
<tr>
<td>Enter Your Name : </td>
<td><input type="text" name="txtuname" /></td>
</tr>
<tr>
<td>Enter Password : </td>
<td><input type="password" name="txtpass" /></td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input style="width:100px" type="submit" value="Login" name="btnsubmit" /></td>
</tr>
</table>
</form>
</body>
</html>

Welcome.php

<html>
<head>
<title>Welcome Page</title>
</head>

KAMESH PATEL 100


ROLL NO: 90

<body style="background-color:silver">
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("testDB", $con);

$result = mysql_query("SELECT * FROM login_mast where User_Name='$_POST[txtuname]'");

if($row = mysql_fetch_array($result))
{
session_start();
$_SESSION['username']= $_POST['txtuname'];
echo "Welcome! " . $_SESSION['username'];
echo "<br />";
unset($_SESSION['username']);
session_destroy();
}
else
{
header("Location: login_form.php");
}

mysql_close($con);
?>

</body>
</html>

KAMESH PATEL 101


ROLL NO: 90

OUTPUT :

Login_form.php output :

KAMESH PATEL 102


ROLL NO: 90

Welcome.php output :

KAMESH PATEL 103


ROLL NO: 90

PRACTICAL-6

AIM: Create BOOK REGISTRATION page and SEARCH page for Library Management System.
Take appropriate fields.

Program :

Login_form.php

<html>
<head>
<title>Login Form</title>
</head>
<body>

<form action="login.php" method="post">


<table>
<tr>
<td>Enter Your Name : </td>
<td><input type="text" name="txtuname" /></td>
</tr>
<tr>
<td>Enter Password : </td>
<td><input type="password" name="txtpass" /></td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input style="width:100px" type="submit" value="Login" name="btnsubmit" /></td>
</tr>
</table>
</form>
</body>
</html>

Welcome.php

<html>
<head>
<title>Welcome Page</title>
<style type="text/css">

KAMESH PATEL 104


ROLL NO: 90

body
{
margin-top:100px;
}
</style>
</head>
<body>
<center>

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("testDB", $con);

$result = mysql_query("SELECT * FROM login_mast where User_Name='$_POST[txtuname]'");

while($row = mysql_fetch_array($result))
{
echo "Welcome! " . $row['User_Name'];
echo "<br /><br /><br />";
}

mysql_close($con);
?>

<form action="search_book.php" method="post">


<table>
<tr>
<td>Search here for Book</td>
<td><input type="text" value="" name="txtsearch" /></td>
<td><input style="width:150px" type="submit" name="btnsunmit" value="Search" /></td>
</tr>
</table>
</form>

KAMESH PATEL 105


ROLL NO: 90

<form action="insert_book.php" method="post">


<table>
<tr>
<th colspan="2" style="text-align:center">New Entry for Book</th>
</tr>
<tr>
<td>Book Name : </td>
<td><input type="text" name="txtname" value="" /></td>
</tr>
<tr>
<td>Author : </td>
<td><input type="text" name="txtauthor" value="" /></td>
</tr>
<tr>
<td>Edition : </td>
<td><input type="text" name="txtedition" value="" /></td>
</tr>
<tr>
<td>Price : </td>
<td><input style="width:50px" type="txtprice" name="txtprice" value="" /></td>
</tr>
<tr>
<td colspan="2" style="text-align:center"><input style="width:100px" type="submit"
name="btnsubmit" value="Submit" /></td>
</tr>
</table>
</form>

</center>
</body>
</html>

KAMESH PATEL 106


ROLL NO: 90

Insert_form.php

<html>
<head>
<title>Insert</title>
</head>
<body>

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("testDB", $con);

$sql="INSERT INTO book_mast VALUES


('$_POST[txtname]','$_POST[txtauthor]','$_POST[txtedition]','$_POST[txtprice]')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 row added.";

mysql_close($con);
?>

</body>
</html>

Book_detail.php

<html>
<head>
<title>Book Detail</title>
</head>
<body>

<?php
$con = mysql_connect("localhost","root","");
if (!$con)

KAMESH PATEL 107


ROLL NO: 90

{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("testDB", $con);

$result = mysql_query("SELECT * FROM book_mast where Name='$_POST[txtsearch]'");

while($row = mysql_fetch_array($result))
{
echo "<br />";
echo "<b>Author : </b>" . $row['Author'];
echo "<br />";
echo "<b>Edition : </b>" . $row['Edition'];
echo "<br />";
echo "<b>Price : </b>" . $row['Price'];
}

mysql_close($con);
?>

</body>
</html>

KAMESH PATEL 108


ROLL NO: 90

OUTPUT :

Login_form.php output :

KAMESH PATEL 109


ROLL NO: 90

Search_book.php output :

Book_detail.php output :

KAMESH PATEL 110


ROLL NO: 90

Insert_book.php output :

Book_inserted.php output :

KAMESH PATEL 111

Potrebbero piacerti anche