Web D
Web D
Web D
Page | 1
Chapter-1: HTML Basics
“HTML is a language for describing, organizing, and linking the text, graphics and files
containing other information together.”
HTML HISTORY:
1989 Tim Berner Lee invented www
1991 Tim Berner Lee invented HTML
1993 Dave Ragget drafted HTML+
1995 HTML working group defined HTML 2.0
1997 W3C Recommendation: HTML 3.2
1999 W3C Recommendation: HTML 4.01
2000 W3C Recommendation: XHTML 1.0
2008 WHATWG HTML5 first public draft
2012 WHATWG HTML5 living started
2014 W3C Recommendation: HTML 5
2016 W3C candidate Recommendation: HTML 5.1
2017 W3C candidate Recommendation: HTML 5.1 2nd edition
2017 W3C Recommendation: HTML 5.2
<!Doctype>: represents the document type and inform browser about version of HTML.
Structural markup: Elements used to describe both headings and paragraphs.
Semantic markup: Provides extra information such as emphasis, quotation etc.
Elements: components of webpage. Ex: Body, Title, images etc.
Attributes: Properties of elements. Ex: color, height, width, style etc.
Tags: tells browser how to interpret the data. Ex: <p>...</p>
<u>strong tag:</u>
<br><u>em tag:</u>
<br><u>Quotations tag:</u>
<blockquote cite="http://en.wikipedia.org/wiki/Winnie-the-Pooh">
<p>Did you ever stop to think, and forget to start again?</p>
</blockquote>
<p>As A.A. Milne said, <q>Some people talk to animals. Not many listen though.
That's the problem.</q></p>
<br><u>abbr tag:</u>
<p><cite>A Brief History of Time</cite> by Stephen Hawking has sold over ten million
copies worldwide.</p>
<p>A <dfn>black hole</dfn> is a region of space from which nothing, not even light,
can escape.</p>
<br><u>address tag:</u>
<address>
<p><a href="mailto:homer@example.org">homer@example.org</a></p>
<p>742 Evergreen Terrace, Springfield.</p>
</address>
<p>It was the <del>worst</del> <ins>best</ins> idea she had ever had.</p>
<br><u>s tag:</u>
<p>Laptop computer:</p>
<p><s>Was $995</s></p>
<p>Now only $375</p>
Page | 3
Page | 4
Chapter–2: LIST
1. Ordered List: <ol> tag
2. Unordered List: <ul> tag
3. Definition List:
• <ul> tag
• made up of set of terms along with the definition for each of those terms.
• <dt> : definition terms
• <dd> : definition data
NOTE: Nested lists are allowed in HTML.
<u>Definition List:</u>
<dl>
<dt>Sashimi</dt>
<dd>Sliced raw fish that is served with condiments such as shredded daikon
radish or ginger root, wasabi and soy sauce.</dd>
<dt>Scale</dt>
<dd>A device used to accurately measure the weight of ingredients.</dd>
<dd>A technique by which the scales are removed from the skin of a fish.</dd>
<dt>Scamorze</dt>
<dt>Scamorzo</dt>
<dd>An Italian cheese usually made from whole cow's milk (although it was
traditionally made from buffalo milk).</dd>
</dl>
<u>Nested List:</u>
<ul>
<li>Mousses</li>
<li>Pastries
<ol>
<li>Croissant</li>
<li>Mille-feuille</li>
<li>Palmier</li>
<li>Profiterole</li>
</ol>
</li>
<li>Tarts</li>
</ul>
Page | 5
Chapter–3: LINKS
Links from one part of web page to another part of same web page:
On larger websites it is a good idea to organize your code by placing the pages for each
different section of the site into a new folder.
• Same folder: < a href = “destination.html”>
• Moving into the folder: < a href = “folder_name/destination.html”>
• Moving out of folder: < a href = “../../destination.html>
Note: “../” – out of 1 folder
“../../” – out of 2 folders
“../../../” – out of 3 folder
Page | 6
Email Links:
Page | 7
Opening Links in new window: use “target” attribute with value “_blank.”
Page | 8
Chapter–4: IMAGES
Page | 9
• 3 rules to create images:
1. Save in right format:
• JPEG – different colors and GIF/PNG – few colors
2. Save at right size.
3. Use correct resolution.
• JPGs, GIFs, PNGs belongs to bitmap format made up of lots of miniature
squares. Images on computer are in pixels that are displayed on web
pages at a resolution of 72 ppi (pixels per inch)
• while images in printing materials like books and magazines are made up
dots that are usually printed at 300 dpi (dots per inch).
• Vector Images: differ from bitmap images as they are resolution
independent and created by placing points on grid and drawing lines b/w
points.
• Used for images with line drawings like logos, diagrams, illustration.
• SVG (Scalable Vector graphics) new format to display vector images
directly on web.
Page | 10
• <figure> and <figcaption> attributes: “figure” attribute contains the images and
their captions and “figcaption” attribute allows user to add caption to an image.
Page | 11
Chapter–5: TABLES
• Attributes:
• <tr> - table row
• <td> - table data
• <th> - table heading
• <colspan> - used on <th> or <td> to combine columns (horizontally).
• <rowspan> - used on <th> or <td> to combine rows (vertically).
• <width> - width of table
• <cellpadding> - spacing inside table
• <cellspacing> - spacing b/w cells
• <border> - indicates width if border in pixels.
• <bgcolor> - indicates background color of entire table or cell.
• <th scope = “row”> - specifies heading for row
• <th scope = “col”> - specifies heading for column
• LONG Tables:
• <thead> - heading of table
• <tbody> - Body of table
• <tfoot> - footer of table
• <tr>, <th>, <td> remains same as above.
Page | 12
Chapter–6: FORM
• Attributes:
• action – URL for the page on the server that will receive the info in form.
• method – sending the form.
• get method – values of form are added to end of URL.
• suitable for short forms such as search boxes.
• post method – values are sent in HTTP headers.
• suitable for sensitive info like password, PIN, card details.
• If method attribute id not used, by default get method is used.
• Elements:
• <label>
• <input>
• type = text / password / radio / checkbox.
• name – identifies the form control and is sent along with the
information to the server.
• size – indicates width of text input.
• maxlength – limit the number of characters a user may enter into
text field.
• placeholder – text that will eb shown in text box until user clicks
on it.
• valued – indicates the value that is sent to the server for selected
option.
• checked – indicate which value should be selected when the
page loads. [ value = “checked”]
• <type = “button”>
• value – attribute controls the text that appears on the
button.
• <type = “file”> creates a textbox followed by browse button.
• <type = “image”> - used for image on submit button.
• Attributes: src, width, height
• <type = “date”> - create date input.
• <type = “email”> - create email input
• <type = “url”> - create URL input
• <type = “search”> - create email input
• <textarea>
• name
• cols
• rows
Page | 13
• <select> - drop down list box that allows to select one option from drop
down list.
• name
• size – number of options you want to show at a glance.
• multiple – allows user to select multiple options from list.
[value = “multiple”]
• <option> - element used to specify the options user can select.
• value – option attribute, used to indicate the value that is sent to
server along with name of control.
• selected – option attribute, used to indicate with option to
selected when page loads. [value = “selected”]
• <button>
• <fieldset> - grouping form elements with a line around the edge.
• <legend> - contains caption for fieldset.
Page | 14
Chapter–7: EXTRA MARKUP
• DOCTYPE declaration specifies the browser which version of HTML is being used.
• Comments: <!-- comments goes here -->
• id attribute – uniquely identify that element on the page and should start with a
letter or an underscore.
• class attribute – identify a group of several elements being different from others.
• Block level element: always start on new line. Ex: <h1>, <p>, <ul>, <li>.
• Inline elements: continue on the same line. Ex: <a>, <b>, <em>, <img>.
• <div>: element allows to group a set of elements together in one block-level box.
• <span>: inline equivalent of <div> used where a number of inline elements are
included.
• <iframe>: abbreviation of inline frame, little window that has been cut into your
page and in that window you can see another page.
• src – URL o page to show
• height, width
• scrolling – allows the scrollbar in HTML4 and XHTML, not in HTML 5.
• frameborder
• seamless
• <meta>: contains inside <head> and contains info about the web page.
• Attributes:
• name, content – specifies properties of entire page.
• name = “description” – used by search engine to understand
what page is about and should be max 155 chars.
• “keywords” – comma-separated words that user might search
onto find the page.
• “robots” – indicates whether search engine should add this page
to their search results or not. [value = “nofollow” add this page]
• http -equiv –
• author
• pragma – prevents browser from catching the page. [storing it
locally to save time downloading it on subsequent visits]
• expires – indicates when the page should expire. [date format =
Fri, 04 Apr 2014 23:54:06 GMT]
• Escape Character:
< < < Less than
> > & Greater than
& & & Ampersand
“ &ldquo “ Left double quote
” &rdquo ” Right double quote
Page | 15
Page | 16
Chapter–8: FLASH, VIDEO & AUDIO
• Flash is a very popular technology used to animations, video and audio to websites.
• While creating flash file in Flash authorising environment, file extension - .fla
• In order to use in web page, convert to SWF format. [.swf file]
• Timeline:
Page | 17
• USE of Flash:
• In 2005-6, a set of JavaScript libraries were launched (including prototype,
scrit.aculo.us and jQuery) which made it easier to create animated effects
using JS.
• In 2008, HTML5 introduced <video> and <audio> tags.
Page | 18
Advantage Disadvantage
No need to worry about encoding You need your own server and player I you
video since they allow large range of want to exclusively show the content on
formats. your site.
Cost effective because companies Some hosted services will play their adverts
often charges extra for hosting before your video will begin, or even
videos in your site overlay them.
• Video player need the path to play video, so SWFObject uses JavaScript
variable flashvars to pass this info to Flash Movie.
• Path to movie is supplied in the variable params.
Page | 19
• Adding Video: <video> tag
• src
• poster – image to show while the video is downloading or until user plays
the video.
• width, height
• preload – tells the instruction to browser when page loads.
• none – browser should not load the video until user presses play.
• auto – browser downloads video when page loads.
• metadata – browser just collect info such as size, frame, duration.
• controls – browser supply its own controls for playback.
• autoplay
• loop – video runs in loop
Page | 20
Chapter–9: CSS
• Authors use one CSS file to control the presentation (fonts, colors) and second to
control the layout.
• Selectors – indicate which element the rule applies to.
• Declarations – indicate styling of element in selectors.
• Two parts: property and value
• Property – aspects of elements. Ex: color, font, width, height, border.
• Values – values chosen for properties.
Page | 21
• CSS selectors are case sensitive.
Page | 23
Chapter–10: COLOR
• color
• background-color
• specified in 3 ways:
• RGB values
• HEX codes
• color names
• opacity – values b/w 0.0 and 1.0 [ 0.5 means 50% opacity]
• rgba – ‘a’ indicates opacity and is known as alpha value.
Page | 24
• CSS3: HSL colors – new way to specify colors using Hue, saturation and Lightness values.
NOTE: Brightness and Lightness are different. Brightness offers only black while Lightness
offers both white and black.
Page | 25
Chapter–11: TEXT
• Attributes:
• font-family – list of fonts OR typefaces used in that element.
• font-size – specified in 3 ways:
• pixels (px) – most commonly used.
• percentage – default size = 16px
• EMS – An ‘em’ is equivalent to width of letter ‘m.’
Page | 26
• font-weight – [values = normal, bold]
• font-style – [values = normal, italic, oblique]
• text-transform – changes case of text. [values = uppercase, lowercase,
capitalize]
• text-decoration – [values = none, underline, overline, line-through, blink]
• line-height – set the height of entire line of text.
• Line-height = font-size + leading
• Measured in em.
• Should be 1.4 - 1.5 em.
• Leading – vertical space b/t lines of text measured from bottom
of descender to top of ascender on text.
Page | 27
• text-shadow – Ex: 1px 1px 3px #000000
• 1st value – Horizontal Offset.
• -ve value – position to left
• +ve value – position to right
• 2nd value – Vertical Offset.
• 3rd value – Blur Distance [optional].
• 4th value –color of shadow.
• Print designers refer to size of text in terms of points (pt).
• A pixel roughly equates to a point because a point corresponds to 1/72 of
an inch and most computer displays have a resolution of 72 dots per
inch.
• Units to Type Size: :
NOTE: extra p rule is to help Internet Explorer 6 and 7 display the fonts at right size.
• @font-face – allows to use a font, even if it is not downloaded on system by
specifying the path to a copy of font.
• font-family
• src
• format – format of font, just like format of audio or video.
Values – eot, woff, ttf/otf, svg
Page | 28
• open source fonts: www.fontsquirrel.com, www.fontex.org,
www.openfontlibrary.org
• paid commercial fonts: www.typekit.com, www.kernest.com,
www.fontspring.com
• FontSquirrel allows to convert font formats and also the CSS code for
@font-face.
• Pseudo element – extra value at the end of selector and specify declarations.
• :first-letter
• :first-line
NOTE: ordering MUST be link, visited, hover, active for effective links.
Page | 29
Chapter–11: BOXES
• Box Dimensions -
• width, height
• pixels
• percentage – size of box is relative to size of browser window.
• ems – size of box relative to text within it.
• Limiting Width –
• min-width = smallest size of Box when browser window is narrow.
• max-width = maximum width of Box when browser window is wide.
• Helpful when content of pages are legible (especially on smaller
screens).
• Limiting Height –
• min-height
• max-height
• If the box is not big enough to hold the content, the content expands
outside the box which looks very messy.
Page | 30
• Box Shadow – same as text shadow
• 1st value – Horizontal Offset.
• -ve value – position to left
• +ve value – position to right
• 2 value – Vertical Offset.
nd
NOTE: Chrome, Firefox and Safari support this property using -moz-box-shadow and
-webkit-box-shadow but these are not in CSS specification.
Page | 31
• Border, Margin & Padding –
• border-width –
• either in pixels or one of following values:
• thin
• medium
• thick
• can’t use pecentage
• control indivisual borders:
• border-top-width
• border-right-width
• border-bottom-width
• border-left-width
• values appear in clockwise order: top-right-bottom-left
Page | 32
• border-bottom- style
• border-left- style
• border-color –
• control indivisual:
• border-top-color
• border-right- color
• border-bottom- color
• border-left- color
• ordering – top-right-bottom-left
• HSL can also be used but in CSS3 only. Not in older
versions.
Page | 33
• Elliptical Shapes: specify different distance for
horizontal and vertical parts of rounded corner.
Page | 34
• padding – space b/ content of an element and its border.
• pixels (most common), percentage, ems
• if width is specified for box, padding is added onto the
width of box.
• Indivisual padding is also allowed i.e., padding-top
Page | 35
NOTE:
• padding and margin property are not inherited byb the child elements is the same
way that color value of font-family property.
• margin : 10px 20px >> means left and right margins are 10 px while topo and
bottomare 20px.
[same shorthand for padding]
Page | 36
Chapter–12: LISTS, TABLES AND FORMS
• list-style– shorthand
Page | 37
• Table Properties:
• width
• padding – spacing b/w border of cell and its content
• text-transform – convert content of table headers into UPPER case.
• letter-spacing
• font-size
• border-top, border-bottom – borders above and below the table
headers.
• text-align
• background-color
• :hover – highlight table row when user’s mouse goes over it.
• Tips for styling Tables:
• Give cell padding.
• Distinguish heading.
• Shade alternate rows
• Align numbers to right.
Page | 38
• Styling Forms:
• Text Inputs:
• font-size
• color
• background-color
• border
• border-radius
• :focus – pseudo class to change color of text box when it is being
used
• :hover
• background-image
• Submit Button:
• color
• text-shadow
• border-bottom
• background-color
• :hover
Page | 39
• pointer
• move
• text
• wait
• help
• url(“cursor.gif”)
Page | 40
Chapter–13: IMAGES
• width, height – First name the sizes of images, commonly used throughout the site
i.e., small, medium, large.
• Center Aligning:
• display: block = convert to block level.[ images are by default
inline elements]
• margin: 0px auto = “auto” value centers the image.
• Background:
• background-image – format = url(“ …path…”)
• can be applied to particular element.
Page | 41
• background-repeat – 4 values:
• repeat
• repeat-x : image is repeated horizontally only.
• repeat-y : image is repeated vertically only.
• no-repeat
Page | 42
• background – order:
• color
• image
• repeat
• attachment
• attachment
• Linear Gradient –
• Radial Gradient –
• Conic Gradient
Page | 43
Chapter–14: LAYOUT
Page | 44
Chapter–15: JAVASCRIPT BASICs
• Display: 3 methods -
• document.write() –
• deletes all existing HTML within page.
• Inline coputations are allowed.
Before : After:
• innerHTML –
• writes into HTML element.
• Never deletes existing HTML within page.
• Must be written within <script> tag.
Before: After:
Page | 45
• Inline computations are also allowed.
• window.alert() –
• window keyword is optional.
• In JS, winodw object is global scope object which ,eans that
variables, properties, methods by default belongs to winodw
object.
• console.log() –
• display in browser console using inspect.
• F12 – activate debugging [CHROME: ctrl+Shift+J]
• select “console” and click run again.
Script code: Output:
• DOM Tree:
• model of web page.
• Each node is object with methods and properties.
Page | 46
• Object – thing or entity. Ex: browser window, submit button.
• Properties – characteristics/ attribute of object.
• Events – actions taken by web page visitor.
Ex: onclick, onmouseover, onload etc.
• Methods – task to perform on certain event.
Ex: document.write(), form.submit()
Event Event Handler
click onclick
load onload
unload onunload
mouseover onmouseover
mouseout onmouseout
submit onsubmit
• ACCESS ELEMENTS:
• WORK WITH ELEMENTS:
• Comments:
• Single-line - //…..
• Multi-line - /* …….*/
Redeclaring Redeclaring
Impose Solve
problems problem
Page | 47
• Function: using function keyword.
• Methods: same as function but created inside an object.
• Parameter VS Argument: when the function is declared, the words inside
parenthesis are called Parameters while the values when the function is called and
specific numbers are passed are known as Argument.
Page | 48
• Javascript Objects: A Type of variable that contains many values.
• consist pair of Key and value[ like HTML attributes have name, value]
• Creating Object:
• Add properties later -
• Accessing Object:
• Object.PropertyName
• Object[“PropertyName”]
• Javascript Strings:
• Creation –
• var name = “Govind”;
• var name = new String(“Goind”); // not recommended
• Methods –
str.length() 16
str.indexOf(“om”) 1
str.indexOf(“om”,10) 2
Page | 49
str.lastIndexOf(“om”) 12
str.search(“home”)
str.slice(3,11) ‘e sweet h’
str.substring(3,11) ‘ sweet h’
str.replace(“Home”,”My”) ‘My sweet home ’
str.toUpperCase() ‘MY SWEET HOME ’
str.toLowerCase() ‘my sweet home ’
str.charAt(7) e
str.split(‘ ’) [‘Home’, ‘sweet’, ‘home’, ‘’]
str.trim() ‘Home sweet home’
• Javascript Array:
• Creation –
• var name = new Array(1,2,3,4,5)
• var name = new Array(10);
• var name = [1,2,3,4,5]
• Accessing Elements: name[index]
• Methods:
• array.length()
• array.pop() // removes last element
• array.shift() // removes 1st element
• array.push(“black”) // new length is returned
• array.sort()
• array.reverse()
• delete array[1] // deletes element at index 1
• Math Objects:
• Properties: Math.PI, Math.E
• Methods:
• Math.round()
• Math.sqrt(n)
• Math.ceil()
• Math.floor()
• Math.random()
• Abs, log, min, max, pow, sin, cos,tan
• Date Objects:
• new Date()
• new Date(year, maonth, day, hours, minutes, seconds, milliseconds)
• new Date( milliseconds)
• new Date(date string)
Page | 50
• GET methods: • SET methods:
• getDate() • setDate()
• getDay() • setFullYear()
• getFullYear() • setHours()
• getHours() • setMilliseconds()
• getMilliseconds() • setMinutes()
• getMinutes() • setMonth()
• getMonth() • setSeconds()
• getSeconds() • setTime()
• getTime()
• getTimezoneOffset()
• toDateString()
• toTimeString()
• toString()
• Comparison Operators:
is equal to == ‘hello’ == ‘hello’ returns true
‘hello’ == hello returns true
is not equal to != ‘hello’ != ‘hello’ returns false
strict equal to === ‘3’ === ‘3’ returns true
‘3’ === 3 returns false
strict not equal to !== ‘3’ !== ‘3’ returns false
‘3’ !== 3 returns true
Page | 51
Chapter–15: EVENTS
Page | 52
Page | 53
Chapter–16: ERROR Handling & Debugging
Page | 54
Chapter–17: Form Enhancement & Validation
Page | 55
Chapter–18: JSON
• Advantages:
• Lightweight data exchange format
• Language Independent
• Easy to understand.
• Self-describing.
• Disadvantages:
• Syntax is not forgiving i.e., a missed quote, comma can break the file.
• Can contain malicious content due to JavaScript.
• Syntax:
• Unordered set of key/name and its value.
• Enclosed within curly brackets. { }
• Each pair is separated by comma(,) while key and its value, separated
by colon(:)
• Key/ name should be placed in double quotes (not single quotes).
• JSON Data:
• Creation –
Page | 56
• Access –
• Deletion –
Page | 57
• Debugging –
• console.log()
• ‘Debugger’ keyword – pause the code execution and call the
debugging function.
Page | 58
Chapter–19: XML
HTML XML
Case insensitive case sensitive
Used to create web pages and web Used to store and transport data.
applications.
Tages have predefined meaning. User defined tags.
Based on SGML (Standard Generalized Standalone markup language.
Markup Language) and is subset of it.
Used to display content. Used to structure data.
Can’t deal with data validation alone. Deals with data and its validation.
Provides only one input form at a time Form data can be stored in multiple files.
• Well-formed XML document: XML document that has a Tree structure and follows
all the XML rules.
• XML text files as trees.
• May add more rules by adding DTD or in a schema.
Page | 59
• XML Tree:
• Single root node.
• Generally, Pre-order Traversal are used for getting information out of
tree.
• Before loading XML document. It must be loaded to an XML DOM object through
parser.
• XML Parser:
• checks that all XML rules have been obeyed.
• Converts XML doc to XML DOM object.
• Browsers comes with XML parser.
• Ex: Xerxes (Apache open-source project)
• XML DOM:
• Language independent platform
• Defines standard way for accessing and manipulating XML document.
• Represent XML as tree structure.
• Standard for how to get, change, add and delete XML elements.
• DTD (Document type definitions):
• Markup language to describes the tree structure, elements and
attributes of XML document.
• Two datatypes:
• PCDATA (parsed character data)
• CDATA (character data)
Page | 60
• Advantages –
• helps to verify validity of data.
• Not necessary for XML.
• Can be used for standardization if XML file is large and multiple
users are using same file.
“note.dtd”
Page | 61
PCDATA CDATA
Represent character data parsed by Represent character data that it is
XML parser. treated as raw data.
Characters like ‘<’ and ‘&’. Begins with ‘ <![CDATA[ ’ and ends
Escaped using entity reference. with ‘]]> ’
<example> <example>
This is a < test > <![CDATA[This is a <test>]]>
</example> </example>
• XML Schema:
• XML documents are XML schema.
• Provide more information about document than DTD.
• Data type: string, decimal, integer, Boolean, date, and time.
• Divide elements into simple and complex data types.
• Also determines tree structure.
• Advantages of XML Schema over DTD:
• XML schemas are written in XML, unlike DTD.
• XML schemas support different data type.
• XML schemas format is readable.
• XML schemas can verify data using JavaScript.
Page | 62
Page | 63
Chapter–20: SERVLET
• Web Servers –
• Apache Web Server
• Apache Tomcat Web Server
• IIS Web Sever
• Nginx Web Server
• LightSpeed Web Server
• CGI (Common Gateway Interface) – An interface specification that enables web
servers to execute an external program.
OR
Middleware b/w www servers and external databases and information sources.
• Web servers run the CGI program in separate OS shell which includes
OS envirounment and the process to execute code of CGI program.
• Drawbacks –
• High response time
• Not scalable
• Not always secure or object oriented.
• Platform dependent.
• Servlet – Server-side programs that run on a web or application server and act as
middle layer between a requests coming from web browser and databases or
application on server.
• Servlets don’t fork new process for each request.
• New thread is created for each request.
• Single servlet can handle many requests.
Page | 64
Servlet CGI
Thread based. Process based.
i.e., new request -> new thread i.e., new request ->new process
Codes written in JAVA. Any programming lang.
Object oriented. Not Object Oriented.
portable Not portable
Links directly to server. No direct link.
Can read and set HTTP servers. Neither read nor set HTTP servers
Slower speed Faster speed.
Platform independent Platform dependent
Page | 65
• Advantages –
• Less response time from web browser.
• Each request runs on individual thread.
• Scalable.
• Robust and Object-Oriented.
• Platform independent.
doGet() doPost()
Processes client request using HTTP GET Handles request send by client browsers.
METHOD
Form data is appended to URL User data is send using HTTP request body
name/ value pair and not using URL.
URL limited to 2048 characters includingNo restriction on URL length.
data.
Not used for transfer of sensitive data Sensitive data like Login credentials are
sent using doPost()
Form with user data can be bookmarked
Page | 66
We can retrieve client information of
HttpServletRequest and
HttpServletResponse object using doGet().
public void doGet public void doPost
(HttpServletRequest request, (HttpServletRequest request,
HttpServletResponse response) HttpServletResponse response)
throws ServletException, throws ServletException,
IOException IOException
{ {
// Servlet Code // Servlet Code
} }
• Servlet API –
• Consist of 2 imp packages that encapsulates classes and interfaces:
• javax.servlet
• javax.servlet.http – contains list of classes and interfaces
Interface Name Description
Servlet Declares life cycle method for servlet
ServletConfig Initialize parameters
ServletContext Log events and access information
ServletRequest Read data from client request
ServletResponse Write data from client response
Page | 67
• Servlet API Flow –
HttpservletRequest HttpservletResponse
Extends ServletRequest Inetrface Extends ServletResponse Inetrface
provide request info for HTTP servlet. Set response codes in numeric value.
• 200 depicts successful response.
• 404 depicts file not found.
Breaks down a request into parsed Set headers for response mentioning the
elements such as request URL, query name and value of headers.
arguments and headers. Set redirects is used to issue redirect
to client-end browser.
get methods allow to access various ServletOutputStream() is obtained by
parts of request. calling getOutputStream().
Contains all information of client. Data written to ServletOutputStream goes
back to browser.
Page | 68
• Reading Form data using Servlet –
• getParameter() – single parameter
• getParameterValues() – multiple parameters and returns multiple
values (checkbox)
• getParameterNames() – fetch complete list of all parameters in current
request.
Page | 69
Chapter–21: SESSION & COOKIES
• Session Tracking –
• Session refers to particular interval of time.
• Session tracking is a way to maintain state or data of user.
• Http protocols are stateless, and each request is considered as new
request. So, we need to maintain state using session tracking
techniques.
• Cookies –
• Text files
• Stored in client computer for information tracking.
• Created using Cookie class present in Servlet API.
• addCookie(Cookie ck) – HttpServletResponse interface method
• getCookies() - HttpServletRequest interface method.
• Disadvantages:
• Will not work if cookie is disabled from browser.
• Only textual information can be sent in cookie Object.
Page | 70
Page | 71