Web Technologies Assignments Assignment-1: Name: V.Aravind Class: CSE 3D Roll No: 19R15A0520
Web Technologies Assignments Assignment-1: Name: V.Aravind Class: CSE 3D Roll No: 19R15A0520
Assignment-1
Q1) Create a html document that has two frames in one column. The top frame, which must be 20
percent of the column, must have at least four links to other documents; the bottom frame will display
those documents.The links must be names of the departments in your college;The documents must be
at least five-line description of departments.
Ans: Mainframe.html
<html>
<head>
<tittle> Assignment question</title>
</head>
<frameset> rows= "50%, 50%" border="2">
<frame name="top" src="frame1.html">
<frame name =”bottom” src=””>
<noframes>
</frameset>
</html>
Frame1.html
<html>
<body>
<a href="CSE.html" target = "bottom">CSE</a>
<a href="EEE.html" target= “bottom “>ECE</a><br>
<a href="ECE-.html" target="bottom") EEE</a> <br>
<a href="CIVIL.html" target="bottom">Civil</a>
</body>
</html>
CSE.html
<html>
<body>
<h1> CSE:</h1>
<p> Computer science Engineering encompasses a Variety of topics that relate to computation, like analysis of
algorithms, Programming language, Program design, Software and computer hardware. </p>
<h4> What does a computer science engineer do?</h4>
<P> 1. Design and develop Software application for different industries. </P>
<p>2.Manages the software, hardware and network in any industry </p>
</body>
</html>
ECE.html
<h1>ECE </h₁>
<P> The Electrical & Computer Engineering (ECE) Program prepares you for a wide range of engineering Study
and Career options, including business, biomedical engineering, computer hardware, the aerospace industry,
computer software, nanoelectronic chips, Photonics, nanoengineering, robotics and solar energy harvesting and
distribution.</p>
</body>
</html>
EEE.html
<html>
<body>
<h1> EEE </h1>
<P> B.Tech Electrical and Electronics Engineering is a 4-year Undergraduate course that deals with the study of
electricity, electromagnetism, and their applications in various domains such as transport, appliances,
machinery, etc. After completing B.Tech EEE in India, graduates can pursue further education, research-based
work, or job opportunities in government of private firms.
</p>
</body>
</html>
CIVIL.html
<html>
<body>
<p> Civil Engineers are generally responsible for designing, Constructing and managing Various construction
projects such as roads, building, tunnels, bridges and other. In addition, many Civil Engineers are also involved
conducting research
</p>
</body>
</html>
External CSS
In external CSS, we link the web pages to the external .css file. It is created by text editor. The CSS is more
efficient method for styling a website. By editing the .css file, we can change the whole site at once.
Example program:
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
File: style.css
body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
Inline CSS
Inline CSS is used to style a specific HTML element. Add a style attribute to each HTML tag without using the
selectors. Managing a website may difficult if we use only inline CSS. However, Inline CSS in HTML is useful in
some situations. We have not access the CSS files or to apply styles to element.
Example:
<!DOCTYPE html>
<html>
<body style="background-color:white;">
<h1 style="color:blue;padding:20px;">CSS Tutorials</h1>
<p style="color:blue;">It will be useful here.</p>
</body>
</html>
Q3) "Javascript is event driven" what is meant by event?Show how javascript can handle events?
Ans: Event: The change in the state of an object is known as an event.
Events handle: I'm HTML, there are various events which represent that some activity is performed by the user.
The browser Javascript interaction with HTML is handled through events that occur when the user or the
browser manipulates a pages.The process of reacting over events is called Event Handling.
Some of the event handlers:
Mouse Events:
Onclick: The onclick attribute fires on a mouse click on the element.
Syntax:
<element onclick=”script”>
Example:
<p id="demo" onclick="myFunction()"> Click on me to change text color</p>
<script>
function myFunction() {
document.getElementById("demo").style.color = "red";
}
</script>
OnMouseover:
The onmouseover attribute fires when the mouse pointer moves over an element.
<html>
<head> Javascript Event.
<h1> Java script Event </h1>
</head>
<body>
<script language="javascript" type="text/Javascript”>
Function mouseoverevent(){
alert( This is onmouseover event');
}
</script>
<P onmouseover="mouseoverevent (") Keep Cursor over me </P>
</body>
</html>
Q5) Write a java script to validate a form consisting of name , age, addres, emailID, hobby(check
box),Gender(radio box),country(drop down menu).
Ans:<html>
<head>
<title> Form Validation </title>
<script type="text/Javascript">
function Validate(){
if (document.myform. Name.value()== "") {
alert ("please provide your name !");
document.myform.Name.focus();
return false;
}
if (document.myform.Email.value()== "")
{
alert(“please provide your Email!");
document.myform.Email.focus();
return false;
}
if(document.myform.Country.value()== "")
{
alert (“please provide your country!")
return false;
}
if (document.myForm.age.value() == "")
{
alert ("Please provide your Age!");
document.myform.age.focus();
return false;
}
if (document.myform.address.value()== "") //{
alert ("Please provide your address! " );
document.myform. address.focus();
return false;
}
return (true);
}
</script>
</head>
<body style="padding-left: 525px;">
<form name="myform" onsubmit="return (validate(B));">
Name<input type="text" name="Name><br><br>
Age<input type= "number" name="age"> <br><br>
E-mail<input type="text" name="Email"><br><br>
Gender: <br><input type="radio" name = 'Male' > Male <br>
<input type="radio' name = 'Female'>Female <br>
<input type = 'others' name='others'>others <br> <br>
Hobbies:<br> <br>
<input type="checkbox" name="books"> Reading Books<br><br>
<input type=checkbox" name = "games"> Playing Games <br> <br>
<input type= "checkbox" name="music"> Listening to music <br><br>
Address: <br>
<textarea cols="30" rows="5 name="address"</textarea> <br><br>
Country:
<select name = "Country">
<option value="-1" selected > select country </option>
<option value="1") USA </option>
<option value="2"> UK </option>
<option value="3"> INDIA </option>
<option value = "4"> PAKISTAN </option>
<option value="5"> RUSSIA</option>
</select><br><br>
<input type="submit" value="submit">
<input type="reset" value=cancel">
</form>
</body>
</html>
Assignment -2
Q1. Explain different types of selectors in detail with an example.
Ans: CSS selectors are used to select the content we want to style. css selectors select HTML elements
according to its id,class,type,attribute etc. There are many types of selectors in class. Below are the different
types of class selectors.
a. CSS Element Selector: It selects the HTML element by name
<html>
<head>
<style>
P{ text-align: center;
color: blue
}
</style>
</head>
<body>
<p> Welcome </p>
</body>
</html>
b. CSS ID Selector: It selects the id attribute of an HTML element to select a specific element. Id is unique
within the page so it is chosen to select a unique element written with hash(“#”) character
<html>
<head>
<style>
#p1{ text-align:centre;
Color:blue;
}
</style>
</head>
<body>
<p id=”p1”>Hello</p>
<p>Welcome</p>
</body>
</html>
c. CSS Class Selector: It selects elements with a specific class attribute. It is used with a full stop(.) followed
by class name.
<html>
<head>
<style>
•p1{ text-align: center; color: blue; }
</styles>
</head>
<body>
<h1 class:"p1" > Class selector </h1>
d. CSS Universal Selector: Used as a wildcard character. It selects all the elements on the page.
<html>
<head>
<style>
*{color:blue;}
</style>
<body>
<h2>Universal Selector</h2>
</body>
</html>
e. CSS Group Selector: used to select all the elements with the same style definitions, it is mainly used to
minimize the code. commas(,) are used to separate each selector in grouping.
<html>
<head>
<style>
h1,p{text-align:centre;color:blue;}
</style>
<body>
<h1>Group Selector</h1>
<p>minimizes the code</p>
</body>
</html>
a) break keyword
When the script reaches a break keyword, it breaks out of the switch block. This will stop the execution inside
the switch block. It is not necessary to break the last case.
b) default keyword. It specifies the code to run if there is no case match.
Syntax
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
Example:
switch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
}
Property Description
Example:
<html>
<head> Math Example</head>
<body>
<h1> Math properties</h1>
<p id="GFG"></p>
<script>
document.getElementById("GFG").innerHTML=“Math.LN10:”+Math.LN10+ “<br>" +"Math.LOG2E:
"+Math.LOG2E + "<br> +"Math.LOG10E" +Math.LOG2E + "<br> +
"Math.SQRT2 : " +Math.SQRT2"<br>"+"Math.LN2:”+Math.LN2+“<br>" +“Math.E :“+Math.E+"<br>"
+“Math.PI:”+Math.PI;
</script>
</body>
</html>
Math methods
Method Description
Assignment - 3
Q1) Explain the life cycle of servlets with an example.
The web container maintains the life cycle of a servlet instance. Let's see the life cycle of the servlet:
1. Servlet class is loaded.
2. Servlet instance is created.
3. init method is invoked.
4. service method is invoked.
5. destroy method is invoked.
1) Servlet class is loaded
The classloader is responsible to load the servlet class. The servlet class is loaded when the first request for the
servlet is received by the web container.
// Initializing servelet
public void init() throws ServletException
{
output = "Advance Java Concepts";
}
1. <web-app>
2. <servlet>
3. ......
4.
5. <init-param>
6. <param-name>parametername</param-name>
7. <param-value>parametervalue</param-value>
8. </init-param>
9. ......
10. </servlet>
11. </web-app>
Q3) Write about the methods in the servlet interface.
Servlet interface provides commandbehavior all the servlets.Servlet interface defines methods that all servlets
must implement.
Servlet interface needs to be implemented for creating any servlet (either directly or indirectly). It provides 3 life
cycle methods that are used to initialize the servlet, to service the requests, and to destroy the servlet and 2 non-
life cycle methods.
Methods are:
Method Description
public void init(ServletConfig config) initializes the servlet. It is the life cycle method of servlet
and invoked by the web container only once.
public void destroy() is invoked only once and indicates that servlet is being
destroyed.
public String getServletInfo() returns information about servlet such as writer, copyright,
version etc.
HTTP Description
Request
POST Asks the server to accept the body info attached. It is like GET request with
extra info sent with the request.
HEAD Asks for only the header part of whatever a GET would return. Just like GET
but with no body.
TRACE Asks for the loopback of the request message, for testing or troubleshooting.
PUT Says to put the enclosed info (the body) at the requested URL.
OPTIONS Asks for a list of the HTTP methods to which the thing at the request URL can
respond
HttpResponse methods
Sr.No. Method & Description
4 boolean isCommitted()
Returns a Boolean indicating if the response has been committed.
9 void flushBuffer()
Forces any content in the buffer to be written to the client.
void reset()
10
Clears any data that exists in the buffer as well as the status code and headers.
void resetBuffer()
11
Clears the content of the underlying buffer in the response without clearing
headers or status code.
•In case of Hidden form field a hidden (invisible) textfield is used for maintaining the state of an user.
•In such a case, we store the information in the hidden field and get it from another servlet. This approach is
better if we have to submit form in all pages and we don't want to depend on the browser. It is widely used in the
comment form of a website. In such case, we store page id or page name in the helden field so that each page
can be uniquely identified
3 URL Rewriting
We append a token or identities to the URL of the next Servlet or the next resource. We can send parameter
name/value pairs using the format url?name1= value&name2=value&??
• A name and a value is separated using an equal = sign, a parameter name/ value pair is separated from
another parameter using (&)
When the user click the hyperlink, the parameter name/ value pair will be passed to server.
•From a servlet, we can getParameter() method to obtain a parameter value.
•In such case, container creates a session id for each user. The container uses this id to identify the particular
user. An object of Help Session can be used to perform two tasks.
1. bind objects
2. View and manipulate information about a session, such as the session identifier, creation time, and last
accessed time.
• The Http Servlet Request interface provides two methods to get the object of Http Session
a.public HttpSession getSession(): Returns current session associated with this request.
b. public HttpSession getSession(boolean create): Returns the current Http Session associated with this request.
• Commonly used methods of HttpSession interface
a public String getId()
b. public long getCreationTime ( )
Assignment – 4
Q1) Explain about the components of JSP?
Ans: Structure of JSP Page :
JSPs are composed of standard HTML tags and JSP tags. The structure of JavaServer pages are simple and
easily handled by the servlet engine. In addition to HTML ,you can categorize JSPs as following -
● Directives
● Declarations
● Scriptlets
● Comments
● Expressions
Directives :
A directives tag always appears at the top of your JSP file. It is global definition sent to the JSP engine.
Directives contain special processing instructions for the web container. You can import packages, define error
handling pages or the session information of the JSP page. Directives are defined by using <%@ and %> tags.
Syntax -
<%@ directive attribute="value" %>
Declarations :
This tag is used for defining the functions and variables to be used in the JSP. This element of JSPs contains the
java variables and methods which you can call in expression block of JSP page. Declarations are defined by
using <%! and %> tags. Whatever you declare within these tags will be visible to the rest of the page.
Syntax -
<%! declaration(s) %>
Scriptlets:
In this tag we can insert any amount of valid java code and these codes are placed in _jspService method by the
JSP engine. Scriptlets can be used anywhere in the page. Scriptlets are defined by using <% and %> tags.
Syntax -
<% Scriptlets%>
Comments :
Comments help in understanding what is actually code doing. JSPs provides two types of comments for putting
comment in your page. First type of comment is for output comment which is appeared in the output stream on
the browser. It is written by using the <!-- and --> tags.
Syntax -
<!-- comment text -->
Second type of comment is not delivered to the browser. It is written by using the <%-- and --%> tags.
Syntax -
<%-- comment text --%>
Expressions :
Expressions in JSPs are used to output any data on the generated page. These data are automatically
converted to string and printed on the output stream. It is an instruction to the web container for executing the
code within the expression and replacing it with the resultant output content. For writing expressions in JSP, you
can use <%= and %> tags.
Syntax -<%= expression %>
Q2)Write a JSP with a Bean in Session Scope?
Ans: jsp:useBean
The jsp:useBean action tag is used to locate or instantiate a bean class. bean object of the Bean class is already
created, it doesn't create the bean depending on the scope. But if object of bean is not created, it instantiates the
bean.
Assignment - 5
Q1.List out the Features of PHP?
Ans: Features of php
It is most popular and frequently used world wide scripting language, the main reason of popularity is; It is open
source and very simple.
● Simple
● Faster
● Interpreted
● Open Source
● Case Sensitive
● Simplicity
● Efficiency
● Platform Independent
● Security
● Flexibility
● Familiarity
● Error Reporting
● Loosely Typed Language
● Real-Time Access Monitoring
Simple
It is very simple and easy to use, compare to other scripting language it is very simple and easy, this is widely
used all over the world.
Interpreted
It is an interpreted language, i.e. there is no need for compilation.
Faster
It is faster than other scripting language e.g. asp and jsp.
Open Source
Open source means you no need to pay for use php, you can free download and use.
Platform Independent
PHP code will be run on every platform, Linux, Unix, Mac OS X, Windows.
Case Sensitive
PHP is case sensitive scripting language at time of variable declaration. In PHP, all keywords (e.g. if, else, while,
echo, etc.), classes, functions, and user-defined functions are NOT case-sensitive.
Error Reporting
PHP have some predefined error reporting constants to generate a warning or error notice.
Real-Time Access Monitoring
PHP provides access logging by creating the summary of recent accesses for the user.
Loosely Typed Language
PHP supports variable usage without declaring its data type. It will be taken at the time of the execution based
on the type of data it has on its value.
</form>
<?php endif; ?>
</body>
</html>
Q5) Explain the procedure of connecting to database using PHP with an example?
Ans: PHP MySQL Connect
Since PHP 5.5, mysql connect() extension is deprecated. Now it is recommended to use one of the 2
alternatives.
mysqli_connect()
PDO::__construct()
PHP mysqli_connect()
PHP mysqli_connect() function I used to connect with MySQL
returns resource if connection is established or null
Syntax
resource mysqli_connect (server, username, password)
PHP mysql_close()
PHP mysqli_close() function is used to disconnect with MySQL database connection is closed or false returns
true if
Syntax
bool mysqli_close(resource Sresource link)
PHP mysql_query() function is used to delete record in a table. Since PHP 5.5, mysql_query() function is
deprecated. Now it is recommended to use one of the 2 alternatives.
mysqli_query()
PDO::_query(
Example
<?php
$host='localhost:3306,
$user=" $pass="
$dbname 'test,
$id=2
echo "Record deleted successfully. echo "Could not deleted record" mysqli error($coan).