Professional Documents
Culture Documents
Ip Lab 13 03 (Repaired) Ok With Viva
Ip Lab 13 03 (Repaired) Ok With Viva
Ex.No:1
Image Map
Date:
Aim
Create a web page with the following using HTML
To embed a map in a web page
To fix the hot spots in that map
Show all the related information when the hot spots are clicked.
Prerequisites:
Theory:
Images are not technically inserted into a web page; images are linked to web pages. The <img>
tag creates a holding space for the referenced image.
alt - Specifies an alternate text for the image, if the image for some reason cannot be
displayed
The <map> tag is used to define an image map. An image map is an image with clickable areas.
The required name attribute of the <map> element is associated with the <img>'s usemap
attribute and creates a relationship between the image and the map.
The <map> element contains a number of <area> elements, that defines the clickable areas in the
image map.
Procedure
Program:
Save : imagemap.html
<html>
<head>
<title>Client side image maps</title>
</head>
<body>
</body>
Kolkata.html
<html>
<body bgcolor=yellow>
<p>
<center>
<h2> Kolkata </h2>
</center>
Chennai.html
<html>
<body bgcolor=pink>
<p>
<center>
<h2> Chennai </h2>
</center>
Save: Delhi.html
<html>
<body bgcolor=pink>
<p>
<center>
<h2> Delhi </h2>
</center>
<p>
Delhi is the capital of india.
it was ruled previously by the mughal empires.
</p>
</body>
</html>
Save: Kashmir.html
<html>
Save: Mumbai.html
<html>
<body bgcolor=pink>
<p>
<center>
<h2>Mumbai </h2>
</center>
Output
Result:
Thus the creation of a web page which includes a map and display the related
information when a hot spot is clicked in the map was executed successfully.
Viva-voce
1. Write the syntax and tags about tables.
2. What are the various types of lists?
3. Write the description starts with <dd>.
4. Write about frames.
5. Write the scenario of links.
6. What are HTML tags?
7. Can you list out the linking tags in HTML?
8. Define - HTML
9. Write the syntax of href?
10. Compare HTML and XHTML.
11. What is URL?
12. Differentiate Internet from Intranet.
13. What is the use of frame tags?
14. Write the syntax of table tags.
15. What are the formatting tags?
16. What are the heading tags?
17. How to map the images in HTML?
18. What is the use of marquee tag in HTML?
19. What is meant by web site?
20. Define- webpage
Ex.No:2
Cascading style sheets
Date:
Aim
Create a web page with the following.
Cascading style sheets.
Embedded style sheets.
Inline style sheets. Use our college information for the web pages.
Theory:
What is CSS?
CSS stands for Cascading Style Sheets CSS describes how HTML elements are to be displayed
on screen, paper, or in other media CSS saves a lot of work. It can control the layout of multiple
web pages all at once External stylesheets are stored in CSS files
There are three types of CSS which are given below:
Inline CSS
Internal or Embedded CSS
External CSS
Inline CSS:
Inline CSS contains the CSS property in the body section attached with element is known as
inline CSS. This kind of style is specified within an HTML tag using the style attribute.
Inline - by using the style attribute inside HTML elements
Internal or Embedded CSS:
This can be used when a single HTML document must be styled uniquely. The CSS rule set
should be within the HTML file in the head section i.e the CSS is embedded within the HTML
file.
Internal - by using a <style> element in the <head> section
External CSS:
External CSS contains separate CSS file which contains only style property with the help of tag
attributes (For example class, id, heading, … etc). CSS property written in a separate file
with .css extension and should be linked to the HTML document using link tag. This means that
for each element, style can be set only once and that will be applied across web pages.
External - by using a <link> element to link to an external CSS file
Example:
<link rel="stylesheet" href="styles.css">
Procedure:
The internal style is defined inside the <style> element, inside the head section
Inline style sheets
An inline style may be used to apply a unique style for a single element.
To use inline styles, add the style attribute to the relevant element. The style attribute
can contain any CSS property.
Program:
Cascading style sheets
Save : CASCADE.css
BODY
{
BACKGROUND-COLOR: transparent
}
H1
{
FONT-SIZE: 34pt;
COLOR: maroon;
FONT-STYLE: italic;
FONT-FAMILY: sans-serif;
BACKGROUND-COLOR: transparent;
TEXT-ALIGN: center
}
H2
{
FONT-SIZE: 34pt;
COLOR: olive;
FONT-STYLE: italic;
FONT-FAMILY: sans-serif;
BACKGROUND-COLOR: transparent;
TEXT-ALIGN: center
}
H3
{
FONT-SIZE: 34pt;
COLOR: fuchsia;
FONT-STYLE: italic;
FONT-FAMILY: sans-serif;
TEXT-ALIGN: left
}
H4
{
FONT-SIZE: 34pt;
COLOR: fuchsia;
FONT-STYLE: italic;
FONT-FAMILY: sans-serif;
TEXT-ALIGN: center
}
H5
{
FONT-SIZE: 34pt;
COLOR: blue;
FONT-STYLE: italic;
FONT-FAMILY: sans-serif;
TEXT-ALIGN: center
}
H6
{
FONT-SIZE: 34pt;
COLOR: blue;
FONT-STYLE: italic;
FONT-FAMILY: sans-serif;
TEXT-ALIGN: center
}
P
{
FONT-SIZE: 16pt;
COLOR: #f77fcc;
TEXT-INDENT: 20px;
LINE-HEIGHT: 150%;
FONT-FAMILY: "Book Antique",serif
}
A:link
{
COLOR: blue
}
A:visited
{
COLOR: white
}
A:active
{
COLOR: green
}
A:hover
{
COLOR: yellow;
TEXT-DECORATION: underline
}
UL
{
FONT-SIZE: 12pt;
WIDTH: 50%;
COLOR: lightcoral;
FONT-FAMILY: times new roman;
LIST-STYLE-TYPE: disc;
HEIGHT: 50%;
}
OL
{
FONT-SIZE: 12pt;
COLOR: lightcoral;
FONT-FAMILY: times new roman;
LIST-STYLE-TYPE: decimal
}
<html>
<head>
<title>External CSS</title>
<link rel="stylesheet" href="cascade.css" type="text/css">
</head>
<body>
<h1> DEPATMENT OF CSE</H1>
<H2>CURRENT SEMESTER SUBJECT</H2>
<P> This Is The Eaxaple Program For External CSS The Current
Semester
Consist Of The Follwing Theory Subject And Practicals
</P>
<H3> THEORY SUBJECTS</H3>
<OL><B>
<LI> INTERNET PROGRAMMING </LI>
<LI>ARTIFICIAL INTELLIGENCE </LI>
<LI>MOBILE COMPUTING</LI>
<LI>COMPILER DESIGN</LI>
<LI>DISTRIBUTED SYSTEM</LI>
<li> SOFTWARE TESTING & security </LI>
</ol
<h4>PRACTICALS</H4>
<ul>
</ul>
</body>
</html>
h1{
font-family:monotype corsivar;
font-size:20pt;
font-wetght:bold;
color:#f667549;
text-align:center;
}
p{
linr-height;150%;
text_height: 1 in;
font-size:18pt;
color:#ff4f5f;
text-align:justify;
}
ol{ list-style-type:uper-roman;
font-family:book antiqua;font-size:12 pt;
text-indent:1 in;
}
ul{ list-style-type:uper-roman;
font-family:book antiqua;
font-size:12 pt;
text-indent:1 in;
}
</style>
</head>
<body style="background-color:#9575cc">
<h1>
<marquee>DEPARTMENT OF CSE</marquee></h1>
<h2> SOFTWARE CLASSIFICATION </h2>
<p>
This is the example program for Internal CSS. The software
are classified into system side software and application software </p>
<h3> SYSTEM SOFTWARE</h3>
<ol>
<li> Operating system
<li>Linker & Loader
<li>Compiler
<li>Macro processor
<li>Assembler
</ol>
<h3>APPLICATION SOFTWARE</h3>
<ul>
<li>Banking system
<li>Inventory System
<li>Payroll System
<li>Library System
<li>On-line reservation System
</ul>
</body>
</html>
<html>
<head>
<title> InLline Style Sheet </title>
</head>
<body style="background-color:#9575cc">
<h1 style="font-family:monotype corsivar;
<ol style="
list-style-type:uper-roman;
font-family:book antiqua;font-size:12 pt;
text-indent:1 in;">
<li> Operating system</li>
<li>Linker & Loader </li>
<li>Compiler</li>
<li>Macro processor</li>
<li>Assembler </li>
</ol>
<h3 style ="font:18pt" >APPLICATION SOFTWARE</h3>
<ul style="
list-style-type:uper-roman;
font-family:book antiqua;
font-size:12 pt;
text-indent:1 in;">
<li>Banking system </li>
<li>Inventory System </li>
<li>Payroll System </li>
<li>Library System</li>
<li>On-line reservation System </li>
</ul>
</body>
</html>
Result:
Thus the creation of a web page that displays college information using various style
sheet was successfully executed and verified.
Viva-voce
Ex.No:3
Client Side Validate
Date:
Aim
Validate the Registration, user login, user profile and payment by credit card pages using
JavaScript.
Theory:
JavaScript:
Internal JS: We can add JavaScript directly to our HTML file by writing the code inside the
<script> tag. The <script> tag can either be placed inside the <head> or the <body> tag
according to the requirement.
External JS: We can write JavaScript code in other file having an extension .js and then link this
file inside the <head> tag of the HTML file in which we want to add this code.
Syntax:
<script>
// JavaScript Code
</script>
Procedure
Client Side Programming - Form validation:
1. Start the Program
2. Create the html files and in that page create necessary textboxes.
3. User given input is validated and it is linked to signup button.
4. This script validates text inputs typed and select boxes after something has been
selected.
5. Insert Attributes on the tags are used to determine the validation process.
Top.html:
<html>
<body bgcolor=”pink”>
<br><br>
<marquee><h1 align=”center”><b><u>ONLINE BOOK
STORAGE</u></b></h1></marquee>
</body>
</html>
Right.html:
<html>
<body bgcolor=”pink”>
<br><br><br><br><br>
<h2 align=”center”>
<b><p> welcome to online book storage. Press login if you are having id otherwise press registration.
</p></b></h2>
</body></html>
Left.html:
<html>
<body bgcolor=”pink”>
<h3>
<ul>
<li><a href=”login.html” target=”right”><font color=”black”> LOGIN</font></a></li><br><br>
<li><a href=”profile.html” target=”right”><fontcolor=”black”> USER PROFILE</font></a></li><br>
<br>
<li><a href=”catalog.html” target=”right”><fontcolor=”black”> BOOKS CATALOG</font></a></li>
<br><br>
<li><a href=”scart.html” target=”right”><font color=”black”> SHOPPINGCART</font></a></li><br>
<br>
Login.html:
<html>
<body bgcolor="pink"><br><br><br>
<script language="javascript">
function validate()
{
var flag=1;
if(document.myform.id.value==""||
document.myform.pwd.value=="")
{
flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}
}
</script>
<form name="myform">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id"><br> PASSWORD:<input type="password" name="pwd">
</pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">
<input type="reset" value="clear" >
</form>
</body>
</html>
Profile.html:
<html>
<body bgcolor=”pink”><br><br>
<script language=”javascript”>
function validate()
{
var flag=1;
if(document.myform.name.value==””||
document.myform.addr.value==””||
document.myform.phno.value==””||
document.myform.id.value==””||
document.myform.pwd.value==””)
{
flag=0;
}
var str=document.myform.phno.value;
var x;
for(var i=0;i<str.length;i++)
{
x=str.substr(i,1)
if(!(x<=9))
{
flag=0;
break;
}
}
if(flag==1)
{
alert("VALID INPUT");
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}}
</script>
<form name="myform">
<div align="center"><pre>
NAME :<input type="text" name="name"><br> ADDRESS :<input type="type" name="addr"><br>
CONTACT NUMBER:<iput type="text" name="phno"><br> LOGINID :<input type="text" name="id">
<br> 19
PASSWORD :<input type="password" name="pwd"></pre><br><br>
</div>
<br><br>
<div align="center">
Books catalog :
Scart.html:
<html>
<body bgcolor="pink"><br><br><br>
<script language="javascript">
function validate()
{
var flag=1;
if(document.myform.title.value=="")
{
flag=0;
}
str=document.myform.title.value;
if(str=="c")
{
document.writeln("<body bgcolor=pink>");
document.writeln("title-->c"+" cost-->444");
}
else if(str=="jsp")
{
document.writeln("<body bgcolor=pink>");
document.writeln("title-->jsp"+" cost-->555");
}
else
{
flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}
}
</script>
<form name="myform" >
<div align="center"><pre>
BOOK TITLE :<input type="text" name="title"><br> 21
</pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">
<input type="reset" value="clear">
</form>
</body>
</html>
Shopping cart:
Catalog.html:
<html>
<body bgcolor="pink"><br><br><br>
<script language="javascript">
function validate()
{
var flag=1;
if(document.myform.id.value==""||
document.myform.title.value==""||
document.myform.no.value==""||
document.myform.cost.value==""||
document.myform.date.value=="")
{
flag=0;
}
var str=document.myform.no.value;
var x;
for(var i=0;i<str.length;i++)
{
x=str.substr(i,1)
if(!(x<=9))
{
flag=0;
break;
}
}
str=document.myform.title.value;
var str1=document.myform.cost.value;
if(!((str=="c"&& str1==444) || (str=="jsp" && str1==555)))
{
flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}
}
</script>
<form name="myform" >
<div align="center"><pre>
LOGIN ID :<input type="text" name="id"><br> TITLE :<input type="text" name="title"><br> NO.OF
BOOKS
:<input type="text" name="no"><br>
COST OF BOOK
:<input type="text"name="cost"><br>
DATE :<input type="text" name="date"><br></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">
<input type="reset" value="clear">
</form>
</body>
</html>
x=str.substr(i,1);
if(!(x<=9))
{
flag=0;
break;
}
}
str=document.myform.num.value;
for(var i=0;i<str.lenght;i++)
{
x=str.substr(i,1);
if(!(x<=9))
{
flag=0;
break;
}
}
if(flag==1)
{
alert("VALID INPUT");
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}
}
</script>
<form name="myform">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id"><br> PASSWORD :<input type="password" name="pwd">
<br> AMOUNT :<input type="text" name="amount"><br> CREDITCARDNUMBER:<input
type="PASSWORD"
name="num+"><br></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">
<input type="reset" value="clear" >
</form>
</body>
</html>
Order Conformation
Order.html:
<html>
<head><title>order conformation</title><M/head>
<body bgcolor="cyan">
<center>
<h1><b>AMAZON</h1>
<pre><strong>
<b>Your order Is Conformed
</strong></pre>
<h2><b>THANK YOU</h2>
</center>
</body>
</html>
Result
Thus the program has been implemented and output verified successfully.
Viva-voce
Ex.No:4
Servlets
Date:
Aim:
Write programs in Java using Servlets:
i) To invoke servlets from HTML forms
ii) Session tracking using hidden form fields and Session tracking for a hit
count
Theory:
Procedure:
client.html:
(1) Create a web page using HTML form that contains the fields such as label, text and one
submit button.
(2) Set the URL of the server as the value of form’s action attribute.
(3) Run the HTML program.
(4) Submit the form data to the server.
server.java:
(1) Define the class server that extends the property of the class GenericServlet.
(2) Handle the request from the client by using the method service() of GenericServlet class.
(3) Get the parameter names from the HTML form by using the method getParameterNames().
(4) Get the parameter values from the HTML forms by using the method getParameter().
(5) Send the response to the client by using the method of PrintWriter class.
Program:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyServletHtmlDemo extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res) throws
ServletException,IOException
{
PrintWriter out = res.getWriter();
Enumeration en = req.getParameterNames();
while(en.hasMoreElements())
{
String name=(String)en.nextElement();
out.print(name+"=");
String value=req.getParameter(name);
out.println(value);
out.println(" ");
}
}
}
web.xml:
<web-app>
<servlet>
<servlet-name>MyServletHtmlDemo</servlet-name>
<servlet-class>MyServletHtmlDemo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServletHtmlDemo</servlet-name>
<url-pattern>/MyServletHtmlDemo</url-pattern>
</servlet-mapping>
</web-app>
MyServletHtmlDemo.HTML:
<html>
<head>
<title>Student Information Form</title>
</head>
<body>
<center>
ii) Session tracking using hidden form fields and Session tracking for a hit count
Procedure:
client.html:
1. Create a web page using HTML form that contains the fields such as hidden input
tag and submitd button.
2. Set the URL of the server as the value of form’s action attribute.
3. Run the HTML program.
4. Submit the form data to the server.
Servlet: (Server)
1. Servlet program to keep track of user visiting the page.
2. The count is incremented by one when user visits.
3. The output displays the greeting message.
4. The number of previous access is also displayed.
Program:
Save: index.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>Servlet 3.0 Hidden Field Example</title>
<style type="text/css">
.paddingBtm {
padding-bottom: 12px;
}
</style>
</head>
<body>
<center>
<h2>Click the Submit button to check the hidden
field</h2>
<form name="hiddenForm" method="post"
action="hiddenFieldServlet">
<div class="paddingBtm">
<input id="nameId" type="hidden" name="name1"
value="P.T.Lee CNCET" />
</div>
<div id="loginBtn">
Save: Web.xml
<web-app>
<servlet>
<servlet-name>hiddenFieldServlet</servlet-name>
<servlet-class>hiddenFieldServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hiddenFieldServlet</servlet-name>
<url-pattern>/hiddenFieldServlet</url-pattern>
</servlet-mapping>
</web-app>
Save: hiddenFieldServlet.java
String docType =
"<!doctype html public \"-//w3c//dtd html 4.0 " +
"transitional//en\">\n";
out.println(docType +
"<html>\n" +
"<head><title>" + title + "</title></head>\n" +
"<th>Session info</th><th>value</th></tr>\n"
+
"<tr>\n" +
" <td>id</td>\n" +
" <td>" + session.getId() + "</td></tr>\n"
+
"<tr>\n" +
" <td>Creation Time</td>\n" +
" <td>" + createTime + " </td> </tr>\n"
+
"<tr>\n" +
" <td>Time of Last Access</td>\n" + "
<td>" + lastAccessTime +
" </td> </tr>\n" +
"<tr>\n" +
" <td>User ID</td>\n" +
" <td>" + userID + " </td>
</tr>\n" +
"<tr>\n" +
" <td>Number of visits</td>\n" +
" <td>" + visitCount + "</td>
</tr>\n" +
"</table>\n" + "</body>
</html>"
);
}
}
Result
Thus the program has been implemented and output verified successfully.
Viva-voce
Ex.No: 5
Three-Tier Applications Using Servlets
Date:
Aim:
Write programs in Java to create three-tier applications using servlets for conducting
online examination for displaying student mark list. Assume that student information is available
in a database which has been stored in a database server.
Theory:
Procedure:
Client:
In index.html on the client side declare the contents that you like to transfer to the
server using html form and input type tags.
Create a submit button and close all the included tags.
Server:
Import all necessary packages
Define a class that extends servlet
12. Write some code inside your HTML file. We have created a hyperlink to our Servlet in
our HTML file.
13. Edit web.xml file. In the web.xml file you can see, we have specified the url-pattern and
the servlet-name, this means when Servlet url is accessed our Servlet file will be
executed.
14. Run your application, right click on your Project and select Run.
Program:
Save: index.html
<html>
<head><title>Database Test</title></head>
<body>
<center>
<h1>Online Examination</h1>
</center>
<form action="StudentServlet3" method="POST">
<div align="left"><br></div>
<b>Seat Number:</b> <input type="text" name="Seat_no">
<div align="Right">
<b>Name:</b> <input type="text" name="Name" size="50"><br>
</div>
<br><br>
<b>1. Every host implements transport layer.</b><br/>
<input type="radio" name="group1" value="True">True
<input type="radio" name="group1" value="False">False<br>
<b>2. It is a network layer's responsibility to forward
packets reliably from source to destina- tion</b><br/>
<input type="radio" name="group2" value="True">True
<input type="radio" name="group2" value="False">False<br>
<b>3. Packet switching is more useful in bursty
traffic</b><br/>
<input type="radio" name="group3" value="True">True
<input type="radio" name="group3" value="False">False<br>
<b>4. A phone network uses packet switching</b><br/>
<input type="radio" name="group4" value="True">True
<input type="radio" name="group4" value="False">False<br>
<b>5. HTML is a Protocol for describing web contents</b><br/>
<input type="radio" name="group5" value="True">True
<input type="radio" name="group5" value="False">False<br>
<br><br><br>
<center>
<input type="submit" value="Submit"><br><br>
</center>
</form>
</body>
</html>
SERVLET CODE:
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class StudentServlet3 extends HttpServlet
{
String message,Seat_no,Name,ans1,ans2,ans3,ans4,ans5; int Total=0;
Connection connect; Statement stmt=null; ResultSet rs=null;
public void doPost(HttpServletRequest request,HttpServletResponse response) throws
ServletException,IOException
{
try
{
String url="jdbc:mysql://localhost:3306/ex5";
Class.forName("com.mysql.jdbc.Driver");
connect=DriverManager.getConnection(url,"root","");
Total+=2;
if(ans4.equals("False"))
Total+=2;
if(ans5.equals("False"))
Total+=2;
try
{
Statement stmt=connect.createStatement();
String query="INSERT INTO student("+"Seat_no,Name,Total"+")
VALUES('"+Seat_no+"','"+Name+"','"+Total+"')";
int result=stmt.executeUpdate(query); stmt.close();
}catch(SQLException ex){
}
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("</head>");
out.println("<body bgcolor=cyan>");
out.println("<center>");
out.println("<h1>"+message+"</h1>\n");
out.println("<h3>Yours results stored in our database</h3>");
out.print("<br><br>");
out.println("<b>"+"Participants and their Marks"+"</b>");
out.println("<table border=5>");
try
{
Statement stmt=connect.createStatement();
String query="SELECT * FROM student";
rs=stmt.executeQuery(query);
out.println("<th>"+"Seat_no"+"</th>");
out.println("<th>"+"Name"+"</th>");
out.println("<th>"+"Marks"+"</th>");
while(rs.next())
{
out.println("<tr>");
out.print("<td>"+rs.getString(1)+"</td>");
out.print("<td>"+rs.getString(2)+"</td>");
out.print("<td>"+rs.getString(3)+"</td>");
out.println("</tr>");
}
out.println("</table>");
}
Save: Web.xml
Output:
Result:
Thus to write java servlet programs to conduct online examination and to display student
mark list available in a database was successfully executed and verified.
Viva-voce
Aim:
Install TOMCAT web server.
Convert the static web pages of programs into dynamic webpages using servlets (or JSP)
and cookies. \
Hint: Users information (user id, password, credit card number) would be stored in
web.xml. Each user should have a separate Shopping Cart.
Theory:
Procedure:
Step – 1:
Double click apache-tomcat-8.5.75.exe file to start the installation as shown in the below screen
shot:
Step – 2:
The initial screen you will see is the welcome screen for Apache Tomcat server. Click on Next button
as shown in the below screenshot:
Step – 3:
Next screen is the license agreement screen. Click on I Agree button as shown in the below
screenshot:
Step – 4:
In the next screen you can select different components you want to install. Take care that you have
checked all the boxes as shown in the below screenshot and click on Next button:
Step – 5:
Next screen will be the server’s configuration screen. Change the HTTP Connector Port from 8080
to any other value (4040 in the screenshot) to avoid port number collision with Oracle server (default
port for Oracle is 8080). Also specify a administrator User Name and Password of your choice and
click on Next button as shown in the below screenshot:
Step – 6:
In the next screen we can select the location at which the server will be installed. Leave it to the
default location and click on Install button as shown in the below screenshot:
Step – 7:
In the next screen select the path to Java Virtual Machine (JVM) on your machine which will be
automatically done by the setup. If you don’t see any path, do it manually by clicking on (…) button.
Now, click on Next button as shown in the below screenshot:
Step – 8:
In the next screen we can see the installation progress as shown in the below screenshot:
Step – 9:
Next screen is the installation completion screen. Uncheck Show Readme and click on Finish button
as shown in the below screenshot
Step – 10:
To check whether the server is running or not, click the arrow in the system tray and search for the
icon shown in the screenshot. If the icon is displaying a small green arrow as shown in the
screenshot, then your Apache Tomcat server is started. Otherwise you can right click the icon and
click on Start Service option.
Step – 11:
Now, open a browser (ex: Firefox). In the address bar type the URL, http://localhost:8081.
Remember that 8081 is the HTTP connector port number we had allocated previously. If you have
given another number, replace 4040 with that number and hit Enter key. If everything is running
smoothly, you will see the following page as shown in the below screenshot:
Procedure
Convert the static web pages of programs into dynamic webpages using servlets (or JSP)
and cookies. Hint: Users information (user id, password, credit card number) would be
stored in web.xml. Each user should have a separate Shopping Cart
Program Code:
Save : index.jsp
<html>
<head>
</head>
<body>
<form action="LoginServlet" method="post">
Enter username:
<input type="text" name="user">
<br>
Enter Password:
<input type="password" name="password">
<br>
Enter Card ID:
<input type="text" name="cardID">
<br>
<br> <br> <br>
<input type="submit" value="login">
</form>
</body>
</html>
Save : web.xml
</init-param>
<init-param>
<param-name>cardIDs</param-name>
<param-value>111,222,333</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>LoginSuccess</servlet-name>
<servlet-class>LoginSuccess</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LoginSuccess</servlet-name>
<url-pattern>/LoginSuccess</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Save : LoginServlet.java
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class LoginServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String usr=request.getParameter("user");
String pwd=request.getParameter("password");
String card=request.getParameter("cardID");
boolean flag=true;
String[] userID=getInitParameter("usernames").split(",");
String[] password=getInitParameter("passwords").split(",");
String[] cardids=getInitParameter("cardIDs").split(",");
int i;
for(i=0;i<userID.length;i++)
{
if(userID[i].equals(usr)&&password[i].equals(pwd)&&cardids[i].equals(card))
{
flag=false;
Cookie MyCookie=new Cookie("CurrentUser", usr);
MyCookie.setMaxAge(60*60);
response.addCookie(MyCookie);
response.sendRedirect("LoginSuccess");
}
}
if(flag==true)
{
out.print("Error");
out.println("<h4>Invalid user,please try again by clicking following link</h4>");
out.println("<a href='http://localhost:8081/ex61/'>"+"index.jsp");
}
}
finally {
out.close();
}
}
}
Save : LoginSuccess.java
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class LoginSuccess extends HttpServlet {protected void doGet(HttpServletRequest
request, HttpServletResponse response)
throws ServletException, IOException {
Cookie[] my_cookies=request.getCookies();
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.print("Login Success");
out.println("<b>");
String userName=null;
if(my_cookies!=null)
{
for(Cookie cookie:my_cookies)
{
if(cookie.getName().equals("CurrentUser"))
userName=cookie.getValue();
}
}
out.print("<h3>Login Success!!!Welcome</h3>");
out.print("<h2>This is a Shopping cart for : "+userName+"</h2>");
out.close();
}
}
Output:
Result:
Thus the conversion of the static web pages into dynamic web pages using
servlets cookies has been executed successfully.
Viva-voce
Ex.No: 7
Books Information
Date:
Aim:
Redo the previous task using JSP by converting the static web pages into dynamic web
pages. Create a database with user information and books information. The books catalogue
should be dynamically loaded from the database.
Procedure:
Field Type
title text
author text
version text
publisher text
cost text
title text
amount text
cno Text
Field Type
name text
addr text
phno int(11)
id text
pwd text
Program Code:
Save: index.html
<html>
<body>
<br><br><br><br><br><br>
<h1 align="center"><u>ONLINE BOOK STORAGE</u></h1><br><br><br>
<h2 align="center"><P><br>
<b> Welcome to online book storage.
Press LOGIN if you are having id
Otherwise press REGISTRATION
</b></P</h2>
<br><br><p>
<div align="center"> <a href="login.html">LOGIN</a><br>
<a href="reg.html">REGISTRATION</a></div></p>
</body>
</html>
Save: catalog.html
<html>
<body><br /><br /><br />
<div align="center">
BOOK TITLE :<input type="text" name="title" /><br />
</div>
<br />
<div align="center">
<input type="submit" value="ok"
name="button1"/>
Save: catalog.jsp
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% out.println("<html><body>");
String title=request.getParameter("title");
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/ex7","root","");
Statement stmt=con.createStatement();
String sqlstmt="select * from book where title=\'"+title+"\'";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
out.println("<div align=\"center\">");
out.println("TITLE :"+rs.getString(1)+"<br>");
out.println("AUTHOR :"+rs.getString(2)+"<br>");
out.println("VERSION :"+rs.getString(3)+"<br>");
out.println("PUBLISHER :"+rs.getString(4)+"<br>");
out.println("COST :"+rs.getString(5)+"<br>");
out.println("</div>");
flag=1;
}
if(flag==0)
{
out.println("<br><br>SORRY INVALID TITLE TRY AGAIN <br><br>");
out.println("<a href=\"catalog.html\">press HERE to RETRY</a>");
}
out.println("</body></html>");
con.close();
%>
Save: login.html
<html>
<body><br /><br /><br />
<form name="myform" method="post" action="login.jsp">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br />
PASSWORD :<input type="password" name="pwd"/></pre>
<br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
Save: login.jsp
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% out.println("<html><body>");
String id=request.getParameter("id");
String pwd=request.getParameter("pwd");
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//Connection con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger");
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/ex7","root","");
Statement stmt=con.createStatement();
String sqlstmt="select id,pwd from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
if(id.equals(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==0)
{
out.println("<br><br>SORRY INVALID ID TRY AGAIN ID<br><br>");
out.println("<a href=\"login.html\">press LOGIN to RETRY</a>");
}
else
{
out.println("<br><br>VALID LOGIN ID<br><br>"); out.println("<h3><ul>");
out.println("<li><a href=\"profile.html\"><fontcolor=\"black\">USER PROFILE</font>
</a></li><br><br>");
out.println("<li><a href=\"catalog.html\"><fontcolor=\"black\">BOOKS
CATALOG</font></a></li><br><br>");
out.println("<li><a href=\"order.html\"><fontcolor=\"black\">ORDER CONFIRMATION</font
</a></li></ul><br><br>");
}
out.println("</body></html>");
con.close();
%>
Save: Order.html
<html>
<body><br /><br />
<form method="post" action="order.jsp">
<div align="center"><pre>
ID
:<input type="text" name="id" /><br />
PASSWORD
:<input type="password" name="pwd" /><br/> TITLE
:<input type="text" name="title" /><br /> NO. OF BOOKS :<input type="text" name="no"
/><br />
DATE
:<input type="text" name="date" /><br />
CREDIT CARD NUMBER :<input type="password" name="cno" /><br
/></pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" name="button1"/>
<input type="reset" value="clear"
name="button2"/>
</div>
</form>
</body>
</html>
Save: Order.jsp
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% int count;
out.println("<html><body>");
String id=request.getParameter("id");
String pwd=request.getParameter("pwd");
String title=request.getParameter("title");
String count1=request.getParameter("no");
String date=request.getParameter("date");
String cno=request.getParameter("cno");
count=Integer.parseInt(count1);
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//Connection con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger");
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/ex7","root","");
Statement stmt=con.createStatement();
String sqlstmt="select id,pwd from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0,amount,x;
while(rs.next())
{
if(id.equals(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==0)
{
out.println("<br><br>SORRY INVALID ID TRY AGAIN ID<br><br>");
Save: Profile.html
<html>
<body><br /><br /><br />
<form name="myform" method="post" action="profile.jsp">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br />
</pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
Save: profile.jsp
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% out.println("<html><body>");
String id=request.getParameter("id");
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//Connection con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger");
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/ex7","root","");
Statement stmt=con.createStatement();
String sqlstmt="select * from login where id="+id+"";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
out.println("<br><br><br>");
while(rs.next())
{
out.println("<div align=\"center\">");
out.println("NAME :"+rs.getString(1)+"<br>");
out.println("ADDRESS :"+rs.getString(2)+"<br>");
out.println("PHONE NO :"+rs.getString(3)+"<br>");
out.println("</div>");
flag=1;
}
if(flag==0)
{
out.println("<br><br>SORRY INVALID ID TRY AGAIN ID<br><br>");
out.println("<a href=\"profile.html\">press HERE to RETRY</a>");
}
out.println("</body></html>");
con.close(); %>
Save:reg.html
<html>
<body><br /><br />
<form name="myform" method="post" action="reg.jsp">
<table align="center" >
<tr>
<td>NAME</td>
<td>:<input type="text" name="name" /></td>
</tr>
<tr>
<td>ADDRESS</td>
<td>:<input type="text" name="addr" /></td>
</tr>
<tr>
<td>CONTACT NUMBER</td>
<td>:<input type="text" name="phno" /></td>
</tr>
<tr>
<td>LOGIN ID</td>
<td>:<input type="text" name="id" /></td>
</tr>
<tr>
<td>PASSWORD</td>
<td>:<input type="password" name="pwd" /></td>
</tr>
</table>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
Save: reg.jsp
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% response.setContentType("text/html");
out.println("<html><body>");
String name=request.getParameter("name");
String addr=request.getParameter("addr");
String phno=request.getParameter("phno");
String id1=request.getParameter("id");
String pwd1=request.getParameter("pwd");
int no=Integer.parseInt(phno);
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//Connection con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger");
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/ex7","root","");
Statement
stmt=con.createStatement();
String sqlstmt="select id, pwd from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
if(id1.equals(rs.getString(1)) && pwd1.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==1)
{
out.println("<br><br>SORRY INVALID ID ALREADY EXITS TRY AGAIN WITH NEW
ID<br><br>");
out.println("<a href=\"reg.html\">press REGISTER to RETRY</a>");
}
else
{ Statement stmt1=con.createStatement();
stmt1.executeUpdate("insert into login
values('"+name+"','"+addr+"',"+no+",'"+id1+"','"+pwd1+"');");
out.println("<br><br>YOUR DETAILS ARE ENTERED<br><br>");
out.println("<a href=\"login.html\">press LOGIN to login</a>");
}
out.println("</body></html>");
con.close();
%>
Output:
Index.html
Login.html
Login.jsp
Save: profile.html
Save: profile.jsp
Save: catlog.jsp
Order.html
Order.jsp
Result
Thus the program has been implemented and output verified successfully.
Viva-voce
1. What Is Apache Tomcat?
2. How Do I Can Change The Default Home Page Loaded By Tomcat?
3. How To We Can Change Tomcat Default Port?
4. What Is Default Session Time Out In Tomcat?
5. Explain Directory Structure Of Tomcat?
6. What Is Tomcat?
7. How Do You Create Multiple Virtual Hosts?
8. Suppose When We Are Starting Startup.bat File Of Tomcat Server It Is Not Started. Dos
Window Appears For A Second Only. What We Need Do?
9. Explain The Concepts Of Tomcat Servlet Container.?
10. Can I Set Java System Properties Differently For Each Webapp?
11. Explain How Servlet Life Cycles?
12. What Is Webservers? Why It Is Used?
13. How To Communicate Between Two Web Servers In Two Diff Systems?
Date: DOCUMENT
Aim:
Create and save an XML document at the server, which contains 10 users Information.
Write a Program, which takes user Id as an input and returns the User details by taking the user
information from the XML document
Procedure:
Save Students information in the XML file on the specific location.
Create and establish the connection between html file and XML file.
Get the user ID as input
Display the student’s information.
Program Code:
Save: index.html
<!DOCTYPE html>
<HTML>
<HEAD>
<TITLE>Searching for XML Elements </TITLE>
<SCRIPT>
function readXMLData()
{
var xmlDocumentObject, id , name , addr, phone, email;
xmlDocumentObject=new XMLHttpRequest();
xmlDocumentObject.open("GET","userlist.xml",false);
xmlDocumentObject.send();
xmlDocumentObject=xmlDocumentObject.responseXML;
id = xmlDocumentObject.getElementsByTagName("userid");
name = xmlDocumentObject.getElementsByTagName("username");
address = xmlDocumentObject.getElementsByTagName("address");
phone = xmlDocumentObject.getElementsByTagName("phone");
email = xmlDocumentObject.getElementsByTagName("email");
for (i = 0; i < id.length; i++)
{
output=id[i].firstChild.nodeValue;
if (output == document.getElementById("myText").value)
Save: userlist.xml
<userlist>
<userid>user01</userid>
<username>Suseendhiran R </username>
<address>KPM</address>
<phone>511518104034</phone>
<email>511518104034@ptleecncet.com</email>
<userid>user02</userid>
<username>Yuvaraj S </username>
<address>Chennai</address>
<phone>511518104035</phone>
<email>511518104035@gmail.com</email>
<userid>user03</userid>
<username>Yuvaraj S </username>
<address>Chennai</address>
<phone>511518104035</phone>
<email>511518104035@gmail.com</email>
<userid>user04</userid>
<username>Yuvaraj S </username>
<address>Chennai</address>
<phone>511518104035</phone>
<email>511518104035@gmail.com</email>
</userlist>
Output:
Result:
Thus the Program takes user id as an input and returns the user details by
taking the user information from the XML document has been executed
successfully.
Viva-voce
Ex.No: 9
PHP Validation & Store A Data In Database
Date:
Aim:
i) Validate the form using PHP regular expression.
ii) PHP stores a form data into database.
Prerequisites:
Theory:
An HTML form contains various input fields such as text box, checkbox, radio buttons,
submit button, and checklist, etc. These input fields need to be validated, which ensures that the
user has entered information in all the required fields and also validates that the information
provided by the user is valid and correct.
There is no guarantee that the information provided by the user is always correct. PHP validates
the data at the server-side, which is submitted by HTML form.
Empty String
Validate String
Validate Numbers
Validate Email
Validate URL
Input length
Procedure:
Create a file named formvaldiate.php
Put it in your web server's root directory (C:\xampp\htdocs)
Open your XAMPP control panel. In case it doesn't appear on your desktop, it is located
in your XAMPP folder
clicking the "Start" button on the actions column. You should see a random PID(s) and
the default port number
Open up your web browser and in the address bar, type localhost.
Typing localhost/ex9/ formvaldiate.php
Program Code:
Formvaldiate.php
<!DOCTYPE HTML>
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<?php
// define variables and set to empty values
$nameErr = $emailErr = $genderErr = $websiteErr = "";
$name = $email = $gender = $comment = $website = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z-' ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
if (empty($_POST["website"])) {
$website = "";
} else {
$website = test_input($_POST["website"]);
// check if URL address syntax is valid
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-
9+&@#\/%=~_|]/i",$website)) {
$websiteErr = "Invalid URL";
}
}
if (empty($_POST["comment"])) {
$comment = "";
} else {
$comment = test_input($_POST["comment"]);
}
if (empty($_POST["gender"])) {
$genderErr = "Gender is required";
} else {
$gender = test_input($_POST["gender"]);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<?php
echo "<h2>Your Input:</h2>";
echo $name;
echo "<br>";
echo $email;
echo "<br>";
echo $website;
echo "<br>";
echo $comment;
echo "<br>";
echo $gender;
?>
</body>
</html>
Output:
Procedure:
Create a file named index.php and insert.php
Put it in your web server's root directory (C:\xampp\htdocs)
Open your XAMPP control panel. In case it doesn't appear on your desktop, it is located
in your XAMPP folder
clicking the "Start" button on the actions column. You should see a random PID(s) and
the default port number
Create the Database
CREATE DATABASE staff
Create the Table
CREATE TABLE college( first_name varchar(30),last_name varchar(30),gender
varchar(30), address varchar(30),email varchar(30));
Open up your web browser and in the address bar, type localhost.
Typing localhost/ex9ii/ index.php
Program Code:
index.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>GFG- Store Data</title>
</head>
<body>
<center>
<h1>Storing Form data in Database</h1>
<form action="insert.php" method="post">
<p>
<label for="firstName">First Name:</label>
<input type="text" name="first_name" id="firstName">
</p>
<p>
<label for="lastName">Last Name:</label>
<input type="text" name="last_name" id="lastName">
</p>
<p>
<label for="Gender">Gender:</label>
<input type="text" name="gender" id="Gender">
</p>
<p>
<label for="Address">Address:</label>
<input type="text" name="address" id="Address">
</p>
<p>
<label for="emailAddress">Email Address:</label>
<input type="text" name="email" id="emailAddress">
</p>
<input type="submit" value="Submit">
</form>
</center>
</body>
</html>
insert.php
<!DOCTYPE html>
<html>
<head>
<title>Insert Page page</title>
</head>
<body>
<center>
<?php
// Check connection
if($conn === false){
die("ERROR: Could not connect. "
. mysqli_connect_error());
}
if(mysqli_query($conn, $sql)){
echo "<h3>data stored in a database successfully."
. " Please browse your localhost php my admin"
. " to view the updated data</h3>";
// Close connection
mysqli_close($conn);
?>
</center>
</body>
</html>
Output:
index.php
insert.php
Result:
Thus the program has been implemented and output verified successfully.
Viva-voce
1. What is PHP?
2. What do the initials of PHP stand for?
3. Which programming language does PHP resemble?
4. What does PEAR stand for?
5. What is the actually used PHP version?
6. How do you execute a PHP script from the command line?
7. How to run the interactive PHP shell from the command line interface?
8. What is the correct and the most two common way to start and finish a PHP block of
code?
9. How can we display the output directly to the browser?
10. What is the main difference between PHP 4 and PHP 5?
11. Is multiple inheritance supported in PHP?
12. What is the meaning of a final class and a final method?
13. How is the comparison of objects done in PHP?
14. How can PHP and HTML interact?
15. What type of operation is needed when passing values through a form or an URL?
16. How can I display text with a PHP script?
17. What should we do to be able to export data into an Excel file?
Ex.No: 10 Write a web service for finding what people think by asking 500
Aim:
Write a web service for finding what people think by asking 500 people’s opinion for any
consumer product.
Prerequisites:
COMMIT;
Open up your web browser and in the address bar, type localhost.
Typing localhost/ex10/index.php
Program:
index.php
<html>
<head>
<style>
body {
font-family: Arial;
width: 550px;
}
.comment-form-container {
background: #F0F0F0;
border: #e0dfdf 1px solid;
padding: 20px;
border-radius: 2px;
}
.input-row {
margin-bottom: 20px;
}
.input-field {
width: 100%;
border-radius: 2px;
padding: 10px;
border: #e0dfdf 1px solid;
}
.btn-submit {
padding: 10px 20px;
background: #333;
border: #1d1d1d 1px solid;
color: #f0f0f0;
font-size: 0.9em;
width: 100px;
border-radius: 2px;
cursor:pointer;
ul {
list-style-type: none;
}
.comment-row {
border-bottom: #e0dfdf 1px solid;
margin-bottom: 15px;
padding: 15px;
}
.outer-comment {
background: #F0F0F0;
padding: 20px;
border: #dedddd 1px solid;
}
span.commet-row-label {
font-style: italic;
}
span.posted-by {
color: #09F;
}
.comment-info {
font-size: 0.8em;
}
.comment-text {
margin: 10px 0px;
}
.btn-reply {
font-size: 0.8em;
text-decoration: underline;
color: #888787;
cursor:pointer;
}
#comment-message {
margin-left: 20px;
color: #189a18;
display: none;
}
</style>
<title>Comment System using PHP and Ajax</title>
<script src="jquery-3.2.1.min.js"></script>
<body>
<h1>Comment System using PHP and Ajax</h1>
<div class="comment-form-container">
<form id="frm-comment">
<div class="input-row">
<input type="hidden" name="comment_id" id="commentId"
placeholder="Name" /> <input class="input-field"
type="text" name="name" id="name" placeholder="Name" />
</div>
<div class="input-row">
<textarea class="input-field" type="text" name="comment"
id="comment" placeholder="Add a Comment"> </textarea>
</div>
<div>
<input type="button" class="btn-submit" id="submitButton"
value="Publish" /><div id="comment-message">Comments Added Successfully!
</div>
</div>
</form>
</div>
<div id="output"></div>
<script>
function postReply(commentId) {
$('#commentId').val(commentId);
$("#name").focus();
}
$("#submitButton").click(function () {
$("#comment-message").css('display', 'none');
var str = $("#frm-comment").serialize();
$.ajax({
url: "comment-add.php",
data: str,
type: 'post',
success: function (response)
{
var result = eval('(' + response + ')');
if (response)
{
$("#comment-message").css('display', 'inline-block');
$("#name").val("");
$("#comment").val("");
$("#commentId").val("");
listComment();
} else
{
alert("Failed to add comments !");
return false;
}
}
});
});
$(document).ready(function () {
listComment();
});
function listComment() {
$.post("comment-list.php",
function (data) {
var data = JSON.parse(data);
if (parent == "0")
{
comments = "<div class='comment-row'>"+
"<div class='comment-info'><span
class='commet-row-label'>from</span> <span class='posted-by'>" + data[i]
['comment_sender_name'] + " </span> <span class='commet-row-label'>at</span> <span
class='posted-at'>" + data[i]['date'] + "</span></div>" +
"<div class='comment-text'>" + data[i]['comment'] + "</div>"+
</html>
db.php
<?php
$conn = mysqli_connect("localhost","root","","ex10");
?>
comment-list.php
<?php
require_once ("db.php");
mysqli_close($conn);
echo json_encode($record_set);
?>
comment-add.php
<?php
require_once ("db.php");
$commentId = isset($_POST['comment_id']) ? $_POST['comment_id'] : "";
$comment = isset($_POST['comment']) ? $_POST['comment'] : "";
$commentSenderName = isset($_POST['name']) ? $_POST['name'] : "";
$date = date('Y-m-d H:i:s');
if (! $result) {
$result = mysqli_error($conn);
}
echo $result;
?>
Output:
Result:
Thus the program has been implemented and output verified successfully.
Viva-voce
1. What is jQuery ?
2. Does jQuery HTML work for both HTML and XML documents ?
3. What are jQuery Selectors ? Give some examples.
4. What are the advantages of jQuery ?
5. What are the methods used to provide effects?
6. Difference between .empty(), .remove() and, .detach() in Jquery ?
7. Is jQuery a JavaScript or JSON library file ?
8. What are the various ajax functions available in Jquery ?
9. Mention the compatible operating systems with jQuery
10. What is jQuery connect ?
11. What are the different technologies used in AJAX?
12. What is Ajax?
13. What is a synchronous request in AJAX?
14. How is Ajax different?
15. Are Ajax applications easier to develop than traditional Web Applications?
16. Do Ajax applications always deliver a better experience than traditional Web
Applications?
17. Does Ajax work with another language?
18. What is an asynchronous request in AJAX?