Ip 13M
Ip 13M
1.Internet protocols
● A Start-line
● Optionally a message-body
3.CSS types
Cascading Style Sheet(CSS) is used to set the style in web pages that contain
HTML elements. It sets the background color, font-size, font-family, color,
… etc property of elements on a web page.
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.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Inline CSS</title>
</head>
<body>
<p style = "color:#009900; font-size:50px;
font-style:italic; text-align:center;">
GeeksForGeeks
</p>
</body>
</html>
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.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Internal CSS</title>
<style>
.main {
text-align:center;
}
.GFG {
color:#009900;
font-size:50px;
font-weight:bold;
}
.geeks {
font-style:bold;
font-size:20px;
}
</style>
</head>
<body>
<div class = "main">
<div class ="GFG">GeeksForGeeks</div>
Form elements
These are the following HTML <form> elements:
● <label>: It defines label for <form> elements.
● <input>: It is used to get input data from the form in various types
such as text, password, email, etc by changing its type.
● <button>: It defines a clickable button to control other elements or
execute a functionality.
● <select>: It is used to create a drop-down list.
● <textarea>: It is used to get input long text content.
● <fieldset>: It is used to draw a box around other form elements and
group the related data.
● <legend>: It defines caption for fieldset elements.
● <datalist>: It is used to specify pre-defined list options for input
controls.
● <output>: It displays the output of performed calculations.
● <option>: It is used to define options in a drop-down list.
● <optgroup>: It is used to define group-related options in a drop-down
list.
UNIT 2
1. Javascript form validation
Form validation normally used to occur at the server, after the client had
entered all the necessary data and then pressed the Submit button. If the
data entered by a client was incorrect or was simply missing, the server
would have to send all the data back to the client and request that the form
be resubmitted with correct information. This was really a lengthy process
which used to put a lot of burden on the server.
JavaScript provides a way to validate form's data on the client's computer
before sending it to the web server. Form validation generally performs two
functions.
● Basic Validation − First of all, the form must be checked to make sure
all the mandatory fields are filled in. It would require just a loop through
each field in the form and check for data.
● Data Format Validation − Secondly, the data that is entered must be
checked for correct form and value. Your code must include appropriate
logic to test correctness of data.
EXAMPLE:
<script type = "text/javascript">
<!--
function validateEmail() {
var emailID = document.myForm.EMail.value;
atpos = emailID.indexOf("@");
dotpos = emailID.lastIndexOf(".");
/pattern/modifiers;
Example:
Expression
Description
s
Quantifier Description
Exception Hierarchy
All exception and error types are subclasses of class Throwable, which is the
base class of the hierarchy. One branch is headed by Exception. This class is
used for exceptional conditions that user programs should catch.
NullPointerException is an example of such an exception. Another branch,
Error is used by the Java run-time system(JVM) to indicate errors having
to do with the run-time environment itself(JRE). StackOverflowError is an
example of such an error.
Types of Exceptions
Java defines several types of exceptions that relate to its various class
libraries. Java also allows users to define their own exceptions.
Exceptions can be categorized in two ways:
1. Built-in Exceptions
○ Checked Exception
○ Unchecked Exception
2. User-Defined Exceptions
B. User-Defined Exceptions:
Sometimes, the built-in exceptions in Java are not able to describe a certain
situation. In such cases, users can also create exceptions, which are called
‘user-defined Exceptions’.
The advantages of Exception Handling in Java are as follows:
1. Provision to Complete Program Execution
2. Easy Identification of Program Code and Error-Handling Code
3. Propagation of Errors
4. Meaningful Error Reporting
5. Identifying Error Types
4. Event handling
An event can be defined as changing the state of an object or behavior by
performing actions. Actions can be a button click, cursor movement,
keypress through the keyboard or page scrolling, etc.
The java.awt.event package can be used to provide various event classes.
Classification of Events
● Foreground Events
● Background Events
1. Foreground Events
Foreground events are the events that require user interaction to generate,
i.e., foreground events are generated due to interaction by the user on
components in Graphic User Interface (GUI). Interactions are nothing but
clicking on a button, scrolling the scroll bar, cursor moments, etc.
2. Background Events
Events that don’t require interactions of users to generate are known as
background events. Examples of these events are operating system
failures/interrupts, operation completion, etc.
Event Handling
It is a mechanism to control the events and to decide what should happen
after an event occur. To handle the events, Java follows the Delegation
Event model.
● Source: Events are generated from the source. There are various
sources like buttons, checkboxes, list, menu-item, choice, scrollbar, text
components, windows, etc., to generate events.
● Listeners: Listeners are used for handling the events generated from
the source. Each of these listeners represents interfaces that are responsible
for handling events.
To perform Event Handling, we need to register the source with the listener.
Listener
Event Class Description
Interface
Uses of JSON
● It is used while writing JavaScript based applications that includes
browser extensions and websites.
● JSON format is used for serializing and transmitting structured data
over network connection.
● It is primarily used to transmit data between a server and web
applications.
● Web services and APIs use JSON format to provide public data.
● It can be used with modern programming languages.
Characteristics of JSON
● JSON is easy to read and write.
● It is a lightweight text-based interchange format.
● JSON is language independent.
{
"id":"07",
"language": "C++",
"edition": "second",
"author": "E.Balagurusamy"
}
]
}
6.Http request
GET: GET request is used to read/retrieve data from a web server. GET
returns an HTTP status code of 200 (OK) if the data is successfully
retrieved from the server.
POST: POST request is used to send data (file, form data, etc.) to the server.
On successful creation, it returns an HTTP status code of 201.
PUT: A PUT request is used to modify the data on the server. It replaces the
entire content at a particular location with data that is passed in the body
payload. If there are no resources that match the request, it will generate
one.
PATCH: PATCH is similar to PUT request, but the only difference is, it
modifies a part of the data. It will only replace the content that you want to
update.
Servlets are grouped under the Advanced Java tree that are used to create
dynamic web applications. Servlets are robust in nature, well scalable and
are primarily used in developing server-side applications. If we go a little
back in time, we would be able to witness that before the introduction of
servlets, CGI (Common Gateway Interface) were used. Amid several
indigenous tasks that a servlet is capable of doing, dynamically performing
client requests and responses are most common. Other tasks that a servlet
can do effectively are:
● Can easily manage/control the application flow.
● Suitable to implement business logic.
● Can effectively balance the load at the server-side.
● Easily generate dynamic web content.
Talking about the types of servlets, there are primarily two types, namely:
1. Generic Servlets
2. HTTP Servlets
There are three potential ways in which we can employ to create a servlet:
1. Implementing Servlet Interface
2. Extending Generic Servlet
3. Extending HTTP Servlet
The entire life cycle of a Servlet is managed by the Servlet container which
uses the javax.servlet.Servlet interface to understand the Servlet object and
manage it. So, before creating a Servlet object, let’s first understand the life
cycle of the Servlet object which is actually understanding how the Servlet
container manages the Servlet object.
Stages of the Servlet Life Cycle: The Servlet life cycle mainly goes through
four stages,
● Loading a Servlet.
● Initializing the Servlet.
● Request handling.
● Destroying the Servlet.
A. Cookies
Cookies are little pieces of data delivered by the web server in the response
header and kept by the browser. Each web client can be assigned a unique
session ID by a web server. Cookies are used to keep the session going.
Cookies can be turned off by the client.
C. URL Rewriting
With each request and return, append some more data via URL as request
parameters. URL rewriting is a better technique to keep session
management and browser operations in sync.
D. HttpSession
A user session is represented by the HttpSession object. A session is
established between an HTTP client and an HTTP server using the
HttpSession interface. A user session is a collection of data about a user that
spans many HTTP requests.
Illustration:
HttpSession session = request.getSession( );
Session.setAttribute("username", "password");
The request must be made. Before sending any document content to the
client, you must first call getSession().
4. Database connectivity
Advantage of JSTL
1. Fast Development JSTL provides many tags that simplify the JSP.
2. Code Reusability We can use the JSTL tags on various pages.
3. No need to use scriptlet tag It avoids the use of scriptlet tag.
JSTL Tags
There JSTL mainly provides five types of tags:
Tag Name Description
Core tags The JSTL core tag provide variable support, URL
management, flow control, etc. The URL for the core tag is
http://java.sun.com/jsp/jstl/core. The prefix of core tag is c.
Function tags The functions tags provide support for string manipulation
and string length. The URL for the functions tags is
http://java.sun.com/jsp/jstl/functions and prefix is fn.
XML tags The XML tags provide flow control, transformation, etc.
The URL for the XML tags is
http://java.sun.com/jsp/jstl/xml and prefix is x.
SQL tags The JSTL SQL tags provide SQL support. The URL for
the SQL tags is http://java.sun.com/jsp/jstl/sql and prefix is
sql.
UNIT 4
1.XML schema
Syntax
You need to declare a schema in your XML document as follows −
Example
The following example shows how to use schema −
<?xml version = "1.0" encoding = "UTF-8"?>
<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema">
<xs:element name = "contact">
<xs:complexType>
<xs:sequence>
<xs:element name = "name" type = "xs:string" />
<xs:element name = "company" type = "xs:string" />
<xs:element name = "phone" type = "xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The basic idea behind XML Schemas is that they describe the legitimate
format that an XML document can take.
Elements
As we saw in the XML - Elements chapter, elements are the building blocks of
XML document. An element can be defined within an XSD as follows −
<xs:element name = "x" type = "y"/>
Definition Types
You can define XML schema elements in the following ways −
Simple Type
Simple type element is used only in the context of the text. Some of the
predefined simple types are: xs:integer, xs:boolean, xs:string, xs:date. For
example −
<xs:element name = "phone_number" type = "xs:int" />
Complex Type
A complex type is a container for other element definitions. This allows you to
specify which child elements an element can contain and to provide some
structure within your XML documents.
Global Types
With the global type, you can define a single type in your document, which
can be used by all other references. For example, suppose you want to
generalize the person and company for different addresses of the company.
Attributes
Attributes in XSD provide extra information within an element. Attributes
have name and type property as shown below −
<xs:attribute name = "x" type = "y"/>
2.DTD
Example:
3.XML parsers
XML Parsers
An XML parser is a software library or package that provides interfaces for
client applications to work with an XML document. The XML Parser is
designed to read the XML and create a way for programs to use XML.
XML parser validates the document and check that the document is well
formatted.
Let's understand the working of XML parser by the figure given below:
Advantages
1) It supports both read and write operations and the API is very simple to
use.
2) It is preferred when random access to widely separated parts of a
document is required.
Disadvantages
1) It is memory inefficient. (consumes more memory because the whole
XML document needs to loaded into memory).
2) It is comparatively slower than other parsers.
Advantages
1) It is simple and memory efficient.
2) It is very fast and works for huge documents.
Disadvantages
1) It is event-based so its API is less intuitive.
2) Clients never know the full information because the data is broken into
pieces.
4.Php from validation
Empty String
The code below checks that the field is not empty. If the user leaves the
required field empty, it will show an error message. Put these lines of code
to validate the required field.
1. if (emptyempty ($_POST["name"])) {
2. $errMsg = "Error! You didn't enter the Name.";
3. echo $errMsg;
4. } else {
5. $name = $_POST["name"];
6. }
Validate String
The code below checks that the field will contain only alphabets and
whitespace, for example - name. If the name field does not receive valid
input from the user, then it will show an error message:
1. $name = $_POST ["Name"];
2. if (!preg_match ("/^[a-zA-z]*$/", $name) ) {
3. $ErrMsg = "Only alphabets and whitespace are allowed.";
4. echo $ErrMsg;
5. } else {
6. echo $name;
7. }
Validate Number
The below code validates that the field will only contain a numeric value.
For example - Mobile no. If the Mobile no field does not receive numeric
data from the user, the code will display an error message:
1. $mobileno = $_POST ["Mobile_no"];
2. if (!preg_match ("/^[0-9]*$/", $mobileno) ){
3. $ErrMsg = "Only numeric value is allowed.";
4. echo $ErrMsg;
5. } else {
6. echo $mobileno;
7. }
Validate Email
A valid email must contain @ and . symbols. PHP provides various methods
to validate the email address. Here, we will use regular expressions to
validate the email address.
The below code validates the email address provided by the user through
HTML form. If the field does not contain a valid email address, then the
code will display an error message:
1. $email = $_POST ["Email"];
2. $pattern =
"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^";
3. if (!preg_match ($pattern, $email) ){
4. $ErrMsg = "Email is not valid.";
5. echo $ErrMsg;
6. } else {
7. echo "Your valid email address is: " .$email;
8. }
Validate URL
The below code validates the URL of website provided by the user via
HTML form. If the field does not contain a valid URL, the code will display
an error message, i.e., "URL is not valid".
1. $websiteURL = $_POST["website"];
2. if
(!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-
a-z0-9+&@#\/%=~_|]/i",$website)) {
3. $websiteErr = "URL is not valid";
4. echo $websiteErr;
5. } else {
6. echo "Website URL is: " .$websiteURL;
7. }
5.Php database
Cookies are small files which are stored on a user’s computer. They are used
to hold a modest amount of data specific to a particular client and website
and can be accessed either by the web server or by the client computer
When cookies were invented, they were basically little documents
containing information about you and your preferences. For instance, when
you select your language in which you want to view your website, the
website would save the information in a document called a cookie on your
computer, and the next time when you visit the website, it would be able to
read a cookie saved earlier. That way the website could remember your
language and let you view the website in your preferred language without
having to select the language again.
A cookie can contain any type of information such as the time when you
visited the website, the items that you added into your shopping basket, all
the links you clicked in website, etc.,
If a cookie is created in a particular website, and you visit another website
later, the latter would not be able to read the contents from the first website,
in other words only the same website that saves information to a cookie can
access it.
Session Cookies: A session cookie only lasts for the duration of users using
the website. A web browser normally deletes session cookies when it quits. A
session cookie expires if the user does not access the website for a period of
time chosen by the server(idle timeout). They only last for the duration of
time we are on the site. If someone comes and uses our computer, they
would not be able to see anything on the sites that use session cookies,
because they need to enter the username and password again.
Third-party cookies: Third party cookies are the cookies being set with the
different domain than the one shown in the address bar. For example, if you
were to visit Sendflowers.com, it may set the cookie for the address of
SomeAdvertiser.com. Later, when you visit RebuidEngines.com it may set
the cookie for SomeAdvertiser.com. Both of these cookies will be used by
SomeAdvertiser.com to ascertain that you are a person who sends flowers
and works on cars. These are used by advertising agencies who have clients
that pay for displaying ads for products and services but don’t want to
waste money displaying them to people who aren’t going to be a customer.
HTTP Cookies: When you send a request to the server, the server sends a
reply in which it embeds the cookie which serves as an identifier to identify
the user. So, next time when you visit the same website, the cookie lets the
server know that you are visiting the website again.
UNIT 5
1.Ajax client-server architecture
Benefits of Ajax
There are 4 main benefits of using Ajax in web applications:
1. Callbacks: Ajax is used to perform a callback, making a quick round
trip to and from the server to retrieve and/or save data without posting the
entire page back to the server. By not performing a full postback and
sending all form data to the server, network utilization is minimized and
quicker operations occur. In sites and locations with restricted bandwidth,
this can greatly improve network performance. Most of the time, the data
being sent to and from the server is minimal. By using callbacks, the server
is not required to process all form elements. By sending only the necessary
data, there is limited processing on the server. There is no need to process
all form elements, process the ViewState, send images back to the client, or
send a full page back to the client.
2. Making Asynchronous Calls: Ajax allows you to make asynchronous
calls to a web server. This allows the client browser to avoid waiting for all
data to arrive before allowing the user to act once more.
3. User-Friendly: Because a page postback is being eliminated, Ajax
enabled applications will always be more responsive, faster and more
user-friendly.
4. Increased Speed: The main purpose of Ajax is to improve the speed,
performance and usability of a web application. A great example of Ajax is
the movie rating feature on Netflix. The user rates a movie and their
personal rating for that movie will be saved to their database without
waiting for the page to refresh or reload. These movie ratings are being
saved to their database without posting the entire page back to the server.
2. WSDL
Features of WSDL
● WSDL is an XML-based protocol for information exchange in
decentralized and distributed environments.
● WSDL definitions describe how to access a web service and what
operations it will perform.
● WSDL is a language for describing how to interface with XML-based
services.
● WSDL is an integral part of Universal Description, Discovery, and
Integration (UDDI), an XML-based worldwide business registry.
● WSDL is the language that UDDI uses.
● WSDL is pronounced as 'wiz-dull' and spelled out as 'W-S-D-L'.
WSDL Usage
WSDL is often used in combination with SOAP and XML Schema to provide
web services over the Internet. A client program connecting to a web service
can read the WSDL to determine what functions are available on the server.
Any special datatypes used are embedded in the WSDL file in the form of
XML Schema. The client can then use SOAP to actually call one of the
functions listed in the WSDL.
History of WSDL
WSDL 1.1 was submitted as a W3C Note by Ariba, IBM, and Microsoft for
describing services for the W3C XML Activity on XML Protocols in March
2001.
WSDL 1.1 has not been endorsed by the World Wide Web Consortium
(W3C), however it has just released a draft for version 2.0 that will be a
recommendation (an official standard), and thus endorsed by the W3C.
3. SOAP
Points to Note
● SOAP is a communication protocol designed to communicate via
Internet.
● SOAP can extend HTTP for XML messaging.
● SOAP provides data transport for Web services.
● SOAP can exchange complete documents or call a remote procedure.
● SOAP can be used for broadcasting a message.
● SOAP is platform- and language-independent.
● SOAP is the XML way of defining what information is sent and how.
● SOAP enables client applications to easily connect to remote services
and invoke remote methods.
Although SOAP can be used in a variety of messaging systems and can be
delivered via a variety of transport protocols, the initial focus of SOAP is
remote procedure calls transported via HTTP.
Other frameworks including CORBA, DCOM, and Java RMI provide similar
functionality to SOAP, but SOAP messages are written entirely in XML and
are therefore uniquely platform- and language-independent.