Notes e commerce

6,267 views
6,164 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
6,267
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
18
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Notes e commerce

  1. 1. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi UNIT 1 1. Explain in detail about the basic internet protocols. The OSI-ISO model consists of 7 layers and at each layer one or more protocols are used to handle the transmission of data. The layers and the associated protocols are given in the table: Layers Name Protocols used 7 Application SSH, FTP, Telnet 6 Presentation HTTP, SNMP, SMTP, POP3 5 Session RPC, named pipes, NETBIOS 4 Transport TCP, UDP 3 Network IP 2 Data Link Ethernet 1 Physical Cat-5 TCP - Transmission Control Protocol The Transmission Control Protocol (TCP) is one of the core protocols of the Internet Protocol Suite. TCP is one of the two original components of the suite, complementing the Internet Protocol (IP), and therefore the entire suite is commonly referred to as TCP/IP. TCP provides reliable, ordered delivery of a stream of bytes from a program on one computer to another program on another computer. TCP is the protocol that major Internet applications such as the World Wide Web, email, remote administration and file transfer rely on. Other applications, which do not require reliable data stream service, may use the User Datagram Protocol (UDP), which provides a datagram service that emphasizes reduced latency over reliability. The TCP is widely used for: • Safety delivery of data • Error detection • Assurance of the correct sequencing of data being received. The TCP protocol is a connection oriented protocol because before sending the data this protocol requires that the two computers have established connections. The TCP allows the transmission by breaking the data into stream of IP packets. These IP packets are numbered so that they can be reassembled properly. Along with the data an acknowledgment is also sent/received to know whether the reliable connection is occurred or not. TCP protocol provides the full duplex communication process. The below shown figure shows the operation of a TCP protocol.
  2. 2. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi The TCP protocol ask the destination whether it can make a connection with the destination and if the destination gives the acknowledgement then the connection will be made by sending an acknowledgement. Then the source machine sends the data in the form of packets and if the packet is received then the acknowledgement message is sent back to the source. While sending the data the source maintains a timer and if the destination did not send the acknowledgement within the time limit it again resends the data to the destination until the acknowledgement is send to the source from the destination. TCP also adds concept of a port, which allows TCP to communicate with many different applications on a machine. TCP header contains port number representing an application program on the destination computer. Some port numbers have standard meanings. Example: port 25 is normally used for email transmitted using the Simple Mail Transfer Protocol (SMTP). Other port numbers are available first-come-first served to any application. Simplified view of communication using TCP/IP Here the port operation is carried out by the TCP protocol.
  3. 3. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi • Mail server on Host B sends a message to TCP software located on Host B. • The TCP software then tells IP software on Host B. • Now from Host A the data is send to TCP software on Host A. TCP software attaches the TCP header to the data. • The data is then sent to the IP software. IP software attaches the IP header to the data. • The encapsulated data with IP and TCP header will then be traversed over the network. It will be sent to the IP software running on the Host A. • Host A will remove the IP header and sent the packet to the TCP software. • The TCP software running on the Host A will remove the TCP header and send only the data to the mail server. Thus mail server running on the Host A accepts the data sent by mail client on Host B. IP – Internet protocol IP is a network layer protocol which consists of addressing information. Using this information the communication between uniquely addressed computers is possible. The internet protocol decomposes the information into packets of standardized size and then reassembles the data at the destination point. The internet protocol route the packet through the successive network and then to the network. The destination to which the data has to be send will be identified by its IP address. • If the source machine wants to send the data to the destination machine, it is necessary to have the IP software to be run on both the machines. The main function of the IP software is to transfer the data from source to destination. • When the source wants to send the data to the destination machine then the source calls the IP software running on it. It encapsulates the data to be transferred to destination along with the IP address of source and destination. The IP software running in source creates a packet. This packet consists of data+IP address of source+IP address of destination+header. • If the destination is on the same network then the packet is transferred over the network. But if it is on another network then these two networks should get connected together by a gateway. In this case source sends message to the gateway. The gateway selects the computer on one of the network to which it is attached and send the packets to the destination machine. • The packet then travels through the network and then reaches the destination. Such traversing is called routing.
  4. 4. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi Routing The sequence of computer that packet travels through from source to destination is called as its route. UDP – User Datagram Protocol UDP is an alternative protocol to TCP that builds on IP. The main feature is the port concept. It does not provide the two-way connection or does not provide guaranteed delivery. Since it is called as unreliable protocol. UDP's stateless nature is also useful for servers answering small queries from huge numbers of clients. Unlike TCP, UDP supports packet broadcast (sending to all on local network) and multicasting (send to all subscribers). Common network applications that use UDP include: the Domain Name System (DNS), streaming media applications such as IPTV, Voice over IP (VoIP), Trivial File Transfer Protocol (TFTP), IP tunneling protocols and many online games. DNS – Domain Naming Service The Domain Name System (DNS) is a hierarchical distributed naming system for computers, services, or any resource connected to the Internet or a private network. It associates various information with domain names assigned to each of the participating entities. Most importantly, it translates domain names meaningful to humans into the numerical identifiers associated with networking equipment for the purpose of locating and addressing these devices worldwide. An often-used analogy to explain the Domain Name System is that it serves as the phone book for the Internet by translating human-friendly computer hostnames into IP addresses. For example, the domain name www.example.com translates to the addresses 192.0.32.10 (IPv4). The Domain Name System makes it possible to assign domain names to groups of Internet resources and users in a meaningful way, independent of each entity's physical location. Because of this, World Wide Web (WWW) hyperlinks and Internet contact information can remain consistent and constant even if the current Internet routing arrangements change or the participant uses a mobile device. Internet domain names are easier to remember than IP addresses such as 208.77.188.166 (IPv4). Users take advantage of this when they recite meaningful Uniform Resource Locators (URLs) and e-mail addresses without having to know how the computer actually locates them. The Domain Name System distributes the responsibility of assigning domain names and mapping those names to IP addresses by designating authoritative name servers for each domain. Authoritative name servers are assigned to be responsible for their particular domains, and in turn can assign other authoritative name. There are two tasks that can be carried out by DNS servers: • Accepting and then requesting the programs to convert domain names into IP addresses. • Accepting and then requesting the other DNS servers to convert domain names to IP addresses.
  5. 5. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi Host names consist of a sequence of Labels separated by dots, e.g., www.example.org. Final label is top-level domain with 2 standard types: Generic : .com, .edu, .org, etc. Country-code : .us, .ca, etc. Domains are divided into second-level domains, which can be further divided into subdomains, etc. E.g., in www.example.com, example is a second-level domain. A host name plus domain name information is called the fully qualified domain name (FQDN) of the computer. Above, www is the host name, www.example.com is the FQDN. nslookup program provides command-line access to DNS (on most systems). Looking up a host name given an IP address is known as a reverse lookup. Note that single host may have multiple IP addresses (and a single IP address can be associated with multiple domain names). Address (or name) returned is the canonical IP address (or name) specified in the DNS system. Other addresses (or names) are considered aliases. FTP – File Transfer Protocol File Transfer Protocol (FTP) is a standard network protocol used to transfer files from one host to another host over a TCP-based network, such as the Internet. FTP is built on client-server architecture and uses separate control and data connections between the client and server. FTP users may authenticate themselves using a clear-text sign-in protocol but can connect anonymously if the server is configured to allow it. In the second age, the first FTP client applications were interactive command-line tools, implementing standard commands and syntax. Graphical user interface clients have since been developed for many of the popular desktop operating systems in use today. There are various issues that must be solved during file transfer. They are: • Client must have an authority to download a particular file. • The hardware and software on both formats on client and server might be different. • The data interpretation and data formats at client and server might be different. FTP uses two connections between client and server. One connection is used for actual file transfer and the other is used for control information. This separation of data and commands makes the FTP more efficient. HTTP – Hyper Text Transfer Protocol The HTTP is a request/response protocol. It is a communication protocol used to transfer the information on local area network and World Wide Web. It’s the network protocol used to deliver all files and other data on the World Wide Web, whether they are HTML files, image files or anything else. A browser is a HTTP client because it sends request to an HTTP server which then sends response back to the client. The standard port for HTTP servers to listen on is 80. The get and post are two popular methods used by HTTP protocol. It is also called as a stateless protocol because this protocol is not able to maintain the previous information.
  6. 6. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi SNMP – Simple Network Management Protocol SNMP is a protocol which enables network administrators to manage network devices and to diagnose network problems. The network management system is based on two main elements: a supervisor and agents. SNMP makes use of UDP connections for transferring the SNMP messages. The supervisor is the terminal at which the network administrator request for network management. The agents are found at the level of each interface connecting the managed devices to the network. With the help of these agents information’s on the different objects can be collected. SMTP – Simple Mail Transfer Protocol It is extensively used for transfer of emails to remote servers. It is an asynchronous protocol because it allows delayed delivery of message. This protocol makes use of port 25. With the help of mail transfer agent and user agent the SMTP sends and receives the email. The mail transfer agent is the interface between email system and local email server. The user agent is user interface client. It allows the user to read email messages by receiving it from the server. POP3 – Post Office Protocol Version 3 POP3 is used by local email clients. POP3 makes use of port 110. The POP3 protocol works only at the receivers end and had no work at the senders end. The POP has two parts: receivers POP and server POP. The client opens TCP connection with receiver’s POP server. This client must be authenticated first by the user name and password. Then the client can receive the emails from the mailbox. 2. Explain in details about some fundamental html elements. • HTML is a language for describing web pages. • HTML stands for Hyper Text Markup Language • HTML is not a programming language, it is a markup language • A markup language is a set of markup tags • HTML uses markup tags to describe web pages HTML Tags HTML markup tags are usually called HTML tags • HTML tags are keywords surrounded by angle brackets like <html> • HTML tags normally come in pairs like <b> and </b> • The first tag in a pair is the start tag, the second tag is the end tag • Start and end tags are also called opening tags and closing tags HTML Documents = Web Pages • HTML documents describe web pages • HTML documents contain HTML tags and plain text
  7. 7. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi • HTML documents are also called web pages The purpose of a web browser (like Internet Explorer or Firefox) is to read HTML documents and display them as web pages. The browser does not display the HTML tags, but uses the tags to interpret the content of the page: <html> <body> <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html> Example Explained • The text between <html> and </html> describes the web page • The text between <body> and </body> is the visible page content • The text between <h1> and </h1> is displayed as a heading • The text between <p> and </p> is displayed as a paragraph Editing HTML HTML can be written and edited using many different editors like Dreamweaver and Visual Studio. .HTM or .HTML File Extension? When you save an HTML file, you can use either the .htm or the .html file extension. There is no difference; it is entirely up to you. HTML Basic - 4 Examples HTML Headings HTML headings are defined with the <h1> to <h6> tags. Example <h1>This is a heading</h1> <h2>This is a heading</h2> <h3>This is a heading</h3> HTML Paragraphs HTML paragraphs are defined with the <p> tag. Example <p>This is a paragraph.</p> <p>This is another paragraph.</p>
  8. 8. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi HTML Links HTML links are defined with the <a> tag. Example <a href="http://www.w3schools.com">This is a link</a> Note: The link address is specified in the href attribute. HTML Images HTML images are defined with the <img> tag. Example <img src="w3schools.jpg" width="104" height="142" /> Note: The name and the size of the image are provided as attributes. HTML Elements HTML documents are defined by HTML elements. An HTML element is everything from the start tag to the end tag: Start tag * Element content End tag * <p> This is a paragraph </p> <a href="default.htm" > This is a link </a> <br /> * The start tag is often called the opening tag. The end tag is often called the closing tag. HTML Element Syntax • An HTML element starts with a start tag / opening tag • An HTML element ends with an end tag / closing tag • The element content is everything between the start and the end tag • Some HTML elements have empty content • Empty elements are closed in the start tag • Most HTML elements can have attributes Tip: You will learn about attributes in the next chapter of this tutorial. Nested HTML Elements Most HTML elements can be nested (can contain other HTML elements). HTML documents consist of nested HTML elements. HTML Document Example <html> <body>
  9. 9. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi <p>This is my first paragraph.</p> </body> </html> The example above contains 3 HTML elements. HTML Example Explained The <p> element: <p>This is my first paragraph.</p> The <p> element defines a paragraph in the HTML document. The element has a start tag <p> and an end tag </p>. The element content is: This is my first paragraph. The <body> element: <body> <p>This is my first paragraph.</p> </body> The <body> element defines the body of the HTML document. The element has a start tag <body> and an end tag </body>. The element content is another HTML element (a p element). The <html> element: <html> <body> <p>This is my first paragraph.</p> </body> </html> The <html> element defines the whole HTML document. The element has a start tag <html> and an end tag </html>. The element content is another HTML element (the body element). Don't Forget the End Tag Some HTML elements might display correctly even if you forget the end tag: <p>This is a paragraph <p>This is a paragraph The example above works in most browsers, because the closing tag is considered optional. Never rely on this. Many HTML elements will produce unexpected results and/or errors if you forget the end tag. Empty HTML Elements HTML elements with no content are called empty elements.
  10. 10. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi <br> is an empty element without a closing tag (the <br> tag defines a line break). Tip: In XHTML, all elements must be closed. Adding a slash inside the start tag, like <br />, is the proper way of closing empty elements in XHTML (and XML). HTML Tip: Use Lowercase Tags HTML tags are not case sensitive: <P> means the same as <p>. Many web sites use uppercase HTML tags. HTML Headings Headings are important in HTML documents. Headings are defined with the <h1> to <h6> tags. <h1> defines the most important heading. <h6> defines the least important heading. Example <h1>This is a heading</h1> <h2>This is a heading</h2> <h3>This is a heading</h3> Browsers automatically add some empty space (a margin) before and after each heading. Coding: <html> <body> <h1>This is heading 1</h1> <h2>This is heading 2</h2> <h3>This is heading 3</h3> <h4>This is heading 4</h4> <h5>This is heading 5</h5> <h6>This is heading 6</h6> </body> </html> Output:
  11. 11. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi Headings Are Important Use HTML headings for headings only. Don't use headings to make text BIG or bold. Search engines use your headings to index the structure and content of your web pages. Since users may skim your pages by its headings, it is important to use headings to show the document structure. H1 headings should be used as main headings, followed by H2 headings, then the less important H3 headings, and so on. HTML Lines The <hr /> tag creates a horizontal line in an HTML page. The hr element can be used to separate content: Example <p>This is a paragraph</p> <hr /> <p>This is a paragraph</p> <hr /> <p>This is a paragraph</p> Coding: <html> <body> <p>The hr tag defines a horizontal rule:</p> <hr /> <p>This is a paragraph</p> <hr /> <p>This is a paragraph</p> <hr /> <p>This is a paragraph</p>
  12. 12. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi </body> </html> Output: HTML Comments Comments can be inserted into the HTML code to make it more readable and understandable. Comments are ignored by the browser and are not displayed. Comments are written like this: Example <!-- This is a comment --> Coding: <html> <body> <!--This comment will not be displayed--> <p>This is a regular paragraph</p> </body> </html> HTML Paragraphs HTML documents are divided into paragraphs. Paragraphs are defined with the <p> tag. Example <p>This is a paragraph</p> <p>This is another paragraph</p>
  13. 13. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi Note: Browsers automatically add an empty line before and after a paragraph. Don't Forget the End Tag Most browsers will display HTML correctly even if you forget the end tag: Example <p>This is a paragraph <p>This is another paragraph Coding: <html> <body> <p>This is<br />a para<br />graph with line breaks</p> </body> </html> Output: HTML Line Breaks Use the <br /> tag if you want a line break (a new line) without starting a new paragraph: Example <p>This is<br />a para<br />graph with line breaks</p> The <br /> element is an empty HTML element. It has no end tag. <br> or <br /> Coding: <html> <body> <p>This is<br />a para<br />graph with line breaks</p> </body>
  14. 14. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi </html> Output: In XHTML, XML, elements with no end tag (closing tag) are not allowed. Even if <br> works in all browsers, writing <br /> instead works better in XHTML and XML applications. HTML Output - Useful Tips You cannot be sure how HTML will be displayed. Large or small screens and resized windows will create different results. With HTML, you cannot change the output by adding extra spaces or extra lines in your HTML code. The browser will remove extra spaces and extra lines when the page is displayed. Any numbers of lines count as one line, and any number of spaces count as one space. HTML Text Formatting Coding: <html> <body> <p><b>This text is bold</b></p> <p><strong>This text is strong</strong></p> <p><big>This text is big</big></p> <p><i>This text is italic</i></p> <p><em>This text is emphasized</em></p> <p><code>This is computer output</code></p> <p>This is<sub> subscript</sub> and <sup>superscript</sup></p> </body> </html> Output:
  15. 15. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi HTML uses tags like <b> and <i> for formatting output, like bold or italic text. These HTML tags are called formatting tags (look at the bottom of this page for a complete reference). Often <strong> renders as <b>, and <em> renders as <i>. However, there is a difference in the meaning of these tags: <b> or <i> defines bold or italic text only. <strong> or <em> means that you want the text to be rendered in a way that the user understands as "important". Today, all major browsers render strong as bold and em as italics. However, if a browser one day wants to make a text highlighted with the strong feature, it might be cursive for example and not bold! HTML Fonts The HTML <font> Tag Should NOT be Used The <font> tag is deprecated in HTML 4, and removed from HTML5. The World Wide Web Consortium (W3C) has removed the <font> tag from its recommendations. In HTML 4, style sheets (CSS) should be used to define the layout and display properties for many HTML elements. The example below shows how the HTML could look by using the <font> tag: Example <p> <font size="5" face="arial" color="red"> This paragraph is in Arial, size 5, and in red text color. </font> </p> <p>
  16. 16. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi <font size="3" face="verdana" color="blue"> This paragraph is in Verdana, size 3, and in blue text color. </font> </p> Coding; <html> <body> <p> <font size="5" face="arial" color="red"> This paragraph is in Arial, size 5, and in red text color. </font> </p> <p> <font size="3" face="verdana" color="blue"> This paragraph is in Verdana, size 3, and in blue text color. </font> </p> <p>The font element is deprecated in HTML 4. Use CSS instead!</p> </body> </html> Output: HTML Style Example - Font, Color and Size The font-family, color, and font-size properties defines the font, color, and size of the text in an element: Example <html> <body>
  17. 17. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi <h1 style="font-family:verdana;">A heading</h1> <p style="font-family:arial;color:red;font-size:20px;">A paragraph.</p> </body> </html> The font-family, color, and font-size properties make the old <font> tag obsolete. Coding: <html> <body> <h1 style="font-family:verdana;">A heading</h1> <p style="font-family:arial;color:red;font-size:20px;">A paragraph.</p> </body> </html> Output: HTML Style Example - Text Alignment The text-align property specifies the horizontal alignment of text in an element: Example <html> <body> <h1 style="text-align:center;">Center-aligned heading</h1> <p>This is a paragraph.</p> </body> </html> The text-align property makes the old <center> tag obsolete. Coding: <html> <body> <h1 style="text-align:center;">Center-aligned heading</h1> <p>This is a paragraph.</p>
  18. 18. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi </body> </html> Output: 3. Basic XHTML syntax and semantics XHTML follows the following syntax Documents in XHTML must always be well-formed All XHTML Document can have only one root element that is <html>all other elements should be nested within the root element. There will be only one parent called a root element which can have its children (sub elements) nested within it. Sub elements must be in pairs and correctly nested within their parent element. The basic document structure is: (doctype) <html xmlns="http://www.vyom.co.in/xhtml"> <head> <title>...</title> ... </head> <body>... </body> </html> Notice the (doctype) and the "xmlns" attribute on the opening html tag. You should also include a character set Meta tag in the <head> element. XHTML elements must be properly nested Wrong: <p>This is our site <em>paragraph.</p></em> Right: <p>This is our site <em>paragraph.</em></p> Since XML is case-sensitive. Tag names must be in lowercase.
  19. 19. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi Wrong: <PRE>Some preformatted text.</PRE> Right: <pre>Some preformatted text.</pre> All Attributes that are used here must be in lower case Wrong: <a HREF="http://www.vyom.co.in"> Right: <a href="http://www.vyom.co.in"> All elements must be closed This includes elements that traditionally do not contain any content, such as images, form inputs, Meta tags, etc. Wrong: <p>Welcome to vyom. <p>This is our website Right: <p>Welcome to vyom..</p> <p>This is our website.</p> Elements which dont have closing tags must be closed with slash inside the tag. <br> becomes <br /> <hr> becomes <hr /> <input type="text">becomes <input type="text" /> All attributes values must be quoted Wrong: <a href=http://www.vyom.co.in>example link</a> Right: <a href="http://www.vyom.co.in">example link</a> Attribute minimization is forbidden Wrong: <input type="checkbox" checked /> Right: <input type="checkbox" checked="checked" />
  20. 20. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi All image tags should have "alt" attributes. Wrong: <img src="kitten.jpg" /> Right: <img src="kitten.jpg" alt="an evil kitten" /> The "id" attributes and the "name" attribute- Element ids which should be unique eventually will replace element names. For now, to ensure backsword-compatibility it is recommended to use both, for example, many of the form fields are accessed by their names. In cascading style sheets and various scripting languages Ids are used. <img src="kitty.jpg" name="kittypic" alt="an evil kitten" /> <img src="kitty.jpg" name="kittypic" alt="an evil kitten" id="kittypic" /> The XHTML DTD defines mandatory elements 4. Briefly explain about the internet. The internet is a global connection of people computers which are linked together by cables and Telephone lines making communication possible among them in a common language. Global connection of interconnected networks. How does internet works? The internet is used to move data between two specific computers. For moving the data between two computers we require - The address of the destination. - A safe mean of moving data in the form of electronic signals There exist a set of rules which governs the sending and receiving of data on the internet. Rules are implemented in two parts in the network software. - Transmission Control Protocol (TCP). - Internet Protocol (IP). It is called TCP/IP Large block of text/ data, the TCP divides into little Data Packets and add some special information like - packet position and Error correction code. To make sure those packets at the destination can reassemble correctly and without any damage to data. The role of IP here is to put destination addressing information on such packets. It is not necessary that all the packets will follow the same path from source to destination. Special machines
  21. 21. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi Routers are used to load balance various paths that exist on networks gateways allows different electronic networks to talk to Internet which TCP/IP Addresses are essential in the internet. The TCP/IP is a mechanism for providing addresses for computers on the internet address has two forms: Person understandable who expressed as words (Domain name) - www.kongu.edu Machine understandable which repressed as numbers - 172.16.2.5. Ex: murali@yahoo.com username@host.subdomain.domain Username - is the name of the Internet account. Host - individual machines at a particular location. Hosts and local networks are grouped together into domains, which are grouped into one or more larger domains. Ex: apartment-> complex -> town -> country. Sub-domains may corresponds to organizations such as NASA or COMPUSERVE such as India comes a large domain ‘in’ SUB-DOMAINS LARGE DOMAINS com - commercial au - Australia net - network usa - USA mil - military in - india org - organization sg - singapore edu - education cn - canada gov - government jp -Japan int - international Internet Addressing Internet Address consists TWO parts 1. Network Address (Net ID) 2. Host Address (Host ID) The IP address is grouped into 8-bits separated by dots. There four types of internet address each 32 bit long: No. of bits in net ID No. of bits in Host ID Format Range CLASS A 8 24 N.H.H.H 1 to 126 CLASS B 16 16 N.N.H.H 127 to 191 CLASS C 24 8 N.N.N.H 192 to 223 CLASS D Multicasting all bits - 224 to 239 CLASS E For Future - 240 to 254 Here N stands for network address and H stands for Host address. In which only CLASS A, B & C are mostly used. These may be used for:
  22. 22. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi • Unicast - Single computer • Multicast - Set of computers all reside in different location • Any-cast - Set of computers all reside in single location. What can I do on Internet? Several activities can be performed if you have access to the Internet: • To Publish research information • To create campus wide information systems • Use it for Teaching • Use it with ISDN for multimedia conferencing • Refer to the pictures of an art gallery • Have an electronic copy of classics such as Alice in wonderland • Have an electronic copy of journals and magazine from the Internet • To meet people around the world • To refer the job listings and requirements • To get free public domain programs, Movies, songs etc. • To send mail at any time Tools and Services on Internet • E-mail - mailbox • Mailing List • Usenet or Newsgroups • File Transfer Protocol (FTP) • Telnet (Remote login) Browsing the internet There are many browsers for the Internet. They are • Internet Explorer ( IE ) • Netscape Navigator • Mosaic etc. Internet Standards There are many standard organizations in the world. The two organizations are: Internet Engineering Task Force(IETF) and World Wide Web Consortium( W3c) IETF is a relatively informal and it standards include TCP/IP, MIME, SMTP. The W3C, by contrast, is a vendor organization, controlled by its dues-paying member corporations and it standards include HTTP, HTML and XML Internet Principles • TCP/IP • UDP
  23. 23. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi • IP Addresses • Domain Names • Domain Name System • Ports • Sockets • URL's 5. Briefly explain about XML XML was designed to transport and store data but HTML was designed to display data. What is XML? • XML stands for eXtensible Markup Language • XML is a markup language much like HTML • XML was designed to carry data, not to display data • XML tags are not predefined. You must define your own tags • XML is designed to be self-descriptive • XML is a W3C Recommendation The Difference between XML and HTML XML is not a replacement for HTML. XML and HTML were designed with different goals: • XML was designed to transport and store data, with focus on what data is • HTML was designed to display data, with focus on how data looks • HTML is about displaying information, while XML is about carrying information. XML Does Not DO Anything Maybe it is a little hard to understand, but XML does not DO anything. XML was created to structure, store, and transport information. The following example is a note to Tove, from Jani, stored as XML: <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> The note above is quite self descriptive. It has sender and receiver information, it also has a heading and a message body. But still, this XML document does not DO anything. It is just information wrapped in tags. Someone must write a piece of software to send, receive or display it.
  24. 24. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi With XML You Invent Your Own Tags The tags in the example above (like <to> and <from>) are not defined in any XML standard. These tags are "invented" by the author of the XML document. That is because the XML language has no predefined tags. The tags used in HTML are predefined. HTML documents can only use tags defined in the HTML standard (like <p>, <h1>, etc.). XML allows the author to define his/her own tags and his/her own document structure. XML is Not a Replacement for HTML XML is a complement to HTML. It is important to understand that XML is not a replacement for HTML. In most web applications, XML is used to transport data, while HTML is used to format and display the data. XML is a software- and hardware-independent tool for carrying information. XML is a W3C Recommendation XML became a W3C Recommendation on February 10, 1998. XML is Everywhere XML is now as important for the Web as HTML was to the foundation of the Web. XML is the most common tool for data transmissions between all sorts of applications. Relationship between SGML, XML, HTML and XHTML. 6. Relative URLs. URLs are used to locate anything, anywhere. Since their scope is so large, they often get very long. It is often the case that we can abbreviate URLs in the form of relative URLs. All the URLs we've looked at until now were absolute URLs. They identified a resource independent of their context. The URL http://WebReference.com/html/ identifies HTML with
  25. 25. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi Style whether it's typed into your browser, scribbled on a napkin in a bar for a friend or just remembered in your head. Relative URLs are a way to identify a resource relative to their context. To give a rough analogy, if you're in your house with some friends and someone asks where your next-door neighbor Mark lives, you'll probably say "Oh, he's next door." You probably wouldn't say "On a planet called Earth, in the United Stated of America, in Acmetown, on 32 Foobar St." if this conversation is taking place in the living room of 31 Foobar St. For one thing, it's a waste of breath. Relative URLs are something like that; they're the equivalent of saying "down the road, turn left, walk on for a few blocks, you can't miss it." They only make sense if they are given within a certain context. And this context is called a Base URL. As we mentioned earlier, relative URLs can only be used with generic URLs like the ones described by the http scheme. The reason for this is that all generic URLs, like those defined by the http scheme, have a pathname. The Base URL of a resource is everything up to and including the last slash in its pathname. Here are some examples: Absolute URL Base URL http://WebReference.com/ http://WebReference.com/ http://WebReference.com/html/ http://WebReference.com/html/ http://WebReference.com/html/about.html http://WebReference.com/html/ http://WebReference.com/foo/bar.html?baz http://WebReference.com/foo/ Table 1: Examples of Base URLs Now, say that in the document http://WebReference.com/html/about.html, I want to refer to the document http://WebReference.com/html/links.html. What I would do is use the relative URL links.html. This will be added to the base URL to form the URL that I want to match. In most cases, figuring the absolute URL from a relative URL is just a matter of concatenating the base URL and the relative URL, as in the example above. There are, however, a few special cases: A directory called .. (two periods) in a relative URL indicates the parent directory, essentially stripping off everything up to the previous slash in the the Base URI. Note that this only has meaning inside the pathname, so you cannot use this notation to go up higher than the root directory. A directory called . (one period) refers to the current directory. A relative URL that begins with / (a slash) always replace the entire pathname of the base URL. A relative URL that begins with // (two slashes) always replaces everything from the hostname onwards. These notations are best illustrated by example, in the following table. The table shows relative URLs which are all assumed to have the base URL http://WebReference.com/html/, and the absolute URLs that they translate into: Relative URI Absolute URI about.html http://WebReference.com/html/about.html tutorial1/ http://WebReference.com/html/tutorial1/
  26. 26. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi tutorial1/2.html http://WebReference.com/html/tutorial1/2.html / http://WebReference.com/ //www.internet.com/ http://www.internet.com/ /experts/ http://WebReference.com/experts/ ../ http://WebReference.com/ ../experts/ http://WebReference.com/experts/ ../../../ http://WebReference.com/ ./ http://WebReference.com/html/ ./about.html http://WebReference.com/html/about.html Table 2: Resolving relative URLs relative to http://WebReference.com/html/ OTHER URL SCHEMES The mailto scheme The mailto scheme is an example of an opaque URI scheme. Mailto URLs identify someone's e-mail address. Their syntax is simple. You have the scheme name, the colon, and then the e-mail address. If you're someone who has a thing for collecting e-mail addresses, you might refer to yourself in the following ways: mailto:stephanos@webreference.com mailto:stephanos@internet.com mailto:sp249@cam.ac.uk mailto:spip@hol.gr mailto:spip@mercator.nrcps.ariadne-t.gr An important note here is that somewhere along the way someone came up with the brilliant idea of including the subject of an e-mail in the URL, like this: mailto:stephanos@webreference.com?subject=Feedback URIs identifies resources, and don't do anything else. A program might process a mailto URL by sending e-mail to the person, but it might do something else instead; add it to your address book, add it to your kill file so you don't see his e-mail, or anything else. There is also a second very important problem with the above syntax: a user agent that doesn't understand it (and there are many) but does understand normal mailto syntax will try to send mail to the address stephanos@webreference.com?subject=Feedback, which is not a valid e- mail address. So even though you might see the above used some times in HTML, don't use it. And if you want to do the world a favor, mail the person who did and tell them not to do it, citing the reasons above. The ftp scheme The ftp scheme is very similar to the http scheme, and is used to locate files available via FTP (File Transfer Protocol). The syntax is very similar to http syntax: ftp://sunsite.unc.edu/pub/Linux/ls-lR.gz The above URL points to the FTP server on sunsite.unc.edu, to the file ls-lR.gz in the /pub/Linux directory. It is also possible to specify a username and optionally, a password for the connection. The syntax is like this:
  27. 27. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi ftp://user@host/path/file ftp://user:password@host/path/file Note that supplying a password like this is sometimes a bad idea. Some people might tell you this is a huge security risk, but this is not really true: a URL like the one above is typed into your browser will only be a risk if someone peeps over your shoulder and sees the password. The password itself is transmitted unencrypted anyway, and can be intercepted in transit. Before you go paranoid about this, remember that if your read your mail through POP (Post Office Protocol), like most people do, then your mail password is also transmitted in the clear. The lesson in this is that if you're going to be paranoid, at least do it for the right reasons. The file scheme The file scheme is used to point to files on your computer. It is slightly tricky, because (most) absolute file URLs aren't really absolute; they're always relative to your computer. However, you can specify the hostname in a file URL. Remember that a URL just tells you where a resource is located, not how to locate it. So this does make sense. If the hostname is omitted, the current host is assumed. If a URL is encountered by a program with a hostname that's different than the one it's working on, it will most likely decide that it cannot access the file, but this has nothing to do with the URL itself. The syntax is again much like the http syntax, only omitting the port numbers, like this: file:///home/stephanos/public_html/myface.jpg file://localhost/temp/install_log.txt Note that the pathname here represents a path name in the local file system, so the slashes are usually replaced by a more appropriate character before the file is accessed. UNIX uses slashes, Windows uses backslashes, Macintosh and other operating systems use other conventions. The news scheme The news scheme is another opaque URL scheme. It is used to refer to Usenet newsgroups or specific messages within these newsgroups. It has two possible syntaxes. One is the name of a Usenet newsgroup, and the other is the message id of a Usenet post. Note that the message id must be entered without the usual angle brackets (< and >). news:comp.infosystems.www.authoring.html news:ba-ciwah-1998Jun4-013702@mud.stack.nl news:* The third example points to all available newsgroups and can be used to refer to Usenet in general. The telnet scheme The telnet scheme has identical syntax to the ftp scheme, with the exception that there is no pathname. Only a hostname, and optionally a port, username and password may be supplied. telnet://stephanos:secret@somehost.internet.com:35/
  28. 28. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi The above indicates a telnet session for user "stephanos" with password "secret" on port 35 of somehost.internet.com. 7. HTML tags. Tag Description DTD Basic <!DOCTYPE> Defines the document type STF <html> Defines an HTML document STF <body> Defines the document's body STF <h1> to <h6> Defines HTML headings STF <p> Defines a paragraph STF <br /> Inserts a single line break STF <hr /> Defines a horizontal line STF <!--...--> Defines a comment STF Formatting <acronym> Defines an acronym STF <abbr> Defines an abbreviation STF <address> Defines contact information for the author/owner of a STF <b> Defines bold text STF <bdo> Overrides the current text direction STF <big> Defines big text STF <blockquote> Defines a long quotation STF <center> Deprecated. Defines centered text TF <cite> Defines a citation STF <code> Defines a piece of computer code STF <del> Defines text that has been deleted from a document STF <dfn> Defines a definition term STF <em> Defines emphasized text STF <font> Deprecated. Defines font, color, and size for text TF <i> Defines italic text STF <ins> Defines text that has been inserted into a document STF <kbd> Defines keyboard input STF <pre> Defines preformatted text STF <q> Defines a short quotation STF <s> Deprecated. Defines strikethrough text TF <samp> Defines sample output from a computer program STF <small> Defines smaller text STF <strike> Deprecated. Defines strikethrough text TF <strong> Defines strong text STF <sub> Defines subscripted text STF <sup> Defines superscripted text STF
  29. 29. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi <tt> Defines teletype text STF <u> Deprecated. Defines underlined text TF <var> Defines a variable STF <xmp> Deprecated. Defines preformatted text Forms <form> Defines an HTML form for user input STF <input /> Defines an input control STF <textarea> Defines a multiline input control (text area) STF <button> Defines a clickable button STF <select> Defines a drop-down list STF <optgroup> Defines a group of related options in a drop-down list STF <option> Defines an option in a drop-down list STF <label> Defines a label for an <input> element STF <fieldset> Groups related elements in a form STF <legend> Defines a caption for a <fieldset> element STF Frames <frame /> Defines a window (a frame) in a frameset F <frameset> Defines a set of frames F <noframes> Defines an alternate content for users that do not TF <iframe> Defines an inline frame TF Images <img /> Defines an image STF <map> Defines an image-map STF <area /> Defines an area inside an image-map STF Links <a> Defines an anchor STF <link /> Defines the relationship between a document and an external resource STF Lists <ul> Defines an unordered list STF <ol> Defines an ordered list STF <li> Defines a list item STF <dir> Deprecated. Defines a directory list TF <dl> Defines a definition list STF <dt> Defines an item in a definition list STF <dd> Defines a description of an item in a definition list STF <menu> Deprecated. Defines a menu list TF Tables <table> Defines a table STF <caption> Defines a table caption STF <th> Defines a header cell in a table STF <tr> Defines a row in a table STF
  30. 30. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi <td> Defines a cell in a table STF <thead> Groups the header content in a table STF <tbody> Groups the body content in a table STF <tfoot> Groups the footer content in a table STF <col /> Defines attribute values for one or more columns in a STF <colgroup> Defines a group of columns in a table for formatting STF Styles <style> Defines style information for a document STF <div> Defines a section in a document STF <span> Defines a section in a document STF Meta Info <head> Defines information about the document STF <title> Defines the document title STF <meta> Defines metadata about an HTML document STF <base /> Specifies the base URL/target for all relative URLs in a document STF <basefont /> Deprecated. Specifies a default color, size, or font for all the text in a document TF Programming <script> Defines a client-side script STF <noscript> Defines an alternate content for users that do not support client-side scripts STF <applet> Deprecated. Defines an embedded applet TF <object> Defines an embedded object STF <param /> Defines a parameter for an object STF 8. HTML forms and frames. HTML FORMS HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons, submit buttons and more. A form can also contain select lists, textarea, fieldset, legend, and label elements. The <form> tag is used to create an HTML form: <form> . input elements . </form> HTML Forms - The Input Element
  31. 31. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi The most important form element is the input element. The input element is used to select user information. An input element can vary in many ways, depending on the type attribute. An input element can be of type text field, checkbox, password, radio button, submit button, and more. The most used input types are described below. Text Fields <input type="text" /> defines a one-line input field that a user can enter text into: <form> First name: <input type="text" name="firstname" /><br /> Last name: <input type="text" name="lastname" /> </form> Note: The form itself is not visible. Also note that the default width of a text field is 20 characters. Password Field <input type="password" /> defines a password field: <form> Password: <input type="password" name="pwd" /> </form> Note: The characters in a password field are masked (shown as asterisks or circles). Radio Buttons <input type="radio" /> defines a radio button. Radio buttons let a user select ONLY ONE of a limited number of choices: <form> <input type="radio" name="sex" value="male" /> Male<br /> <input type="radio" name="sex" value="female" /> Female </form> Checkboxes <input type="checkbox" /> defines a checkbox. Checkboxes let a user select ONE or MORE options of a limited number of choices. <form> <input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br /> <input type="checkbox" name="vehicle" value="Car" /> I have a car </form> Submit Button <input type="submit" /> defines a submit button.
  32. 32. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi A submit button is used to send form data to a server. The data is sent to the page specified in the form's action attribute. The file defined in the action attribute usually does something with the received input: <form name="input" action="html_form_action.asp" method="get"> Username: <input type="text" name="user" /> <input type="submit" value="Submit" /> </form> If you type some characters in the text field above, and click the "Submit" button, the browser will send your input to a page called "html_form_action.asp". The page will show you the received input. HTML FRAMES With frames, you can display more than one HTML document in the same browser window. Each HTML document is called a frame, and each frame is independent of the others. The disadvantages of using frames are: • Frames are not expected to be supported in future versions of HTML • Frames are difficult to use. (Printing the entire page is difficult). • The web developer must keep track of more HTML documents The HTML frameset Element The frameset element holds one or more frame elements. Each frame element can hold a separate document. The frameset element states HOW MANY columns or rows there will be in the frameset, and HOW MUCH percentage/pixels of space will occupy each of them. The HTML frame Element The <frame> tag defines one particular window (frame) within a frameset. In the example below we have a frameset with two columns. The first column is set to 25% of the width of the browser window. The second column is set to 75% of the width of the browser window. The document "frame_a.htm" is put into the first column, and the document "frame_b.htm" is put into the second column: <frameset cols="25%,75%"> <frame src="frame_a.htm" /> <frame src="frame_b.htm" /> </frameset> Note: The frameset column size can also be set in pixels (cols="200,500"), and one of the columns can be set to use the remaining space, with an asterisk (cols="25%,*").
  33. 33. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi UNIT 2 1. What are Literals in JavaScript? Literals are the way you represent values in JavaScript. These are fixed values that we literally provide in your application source, and are not variables. Examples of literals include: 42 3.14159 "To be or not to be" Integers Integers can be expressed in decimal (base 10), hexadecimal (base 16), or octal (base 8) format. A decimal integer literal consists of a sequence of digits (optionally suffixed as described below) without a leading 0 (zero). An integer can be expressed in octal or hexadecimal rather than decimal. A leading 0 (zero) on an integer literal means it is in octal; a leading 0x (or 0X) means hexadecimal. Hexadecimal integers can include digits (0-9) and the letters a-f and A-F. Octal integers can include only the digits 0-7. Floating Point Literals A floating point literal can have the following parts: a decimal integer, a decimal point ("."), a fraction (another decimal number), an exponent, and a type suffix. The exponent part is an "e" or "E" followed by an integer, which can be signed (preceded by a "+" or "-"). A floating point literal must have at least one digit, plus either a decimal point or "e" (or "E"). Some examples of floating point literals are: 3.1415 -3.1E12 .1e12 2E-12 Boolean Literals The boolean type has two literal values: true and false. String Literals A string literal is zero or more characters enclosed in double (") or single (') quotes. A string must be delimited by quotes of the same type; that is, either both single quotes or double quotes. The following are examples of string literals: "blah" 'blah' "1234" "one line n another line" Special Characters We can use the following special characters in JavaScript string literals: b indicates a backspace.
  34. 34. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi f indicates a a form feed. n indicates a new line character. r indicates a carriage return. t indicates a tab character. 2. Describe JavaScript Variables and Data Types. JavaScript Data Types: One of the most fundamental characteristics of a programming language is the set of data types it supports. These are the type of values that can be represented and manipulated in a programming language. JavaScript allows working with three primitive data types: Numbers eg. 123, 120.50 etc. Strings of text e.g. "This text string" etc. Boolean e.g. true or false. JavaScript also defines two trivial data types, null and undefined, each of which defines only a single value. In addition to these primitive data types, JavaScript supports a composite data type known as object. JavaScript Variables: Like many other programming languages, JavaScript has variables. Variables can be thought of as named containers. We can place data into these containers and then refer to the data simply by naming the container. Before we use a variable in a JavaScript program, we must declare it. Variables are declared with the var keyword as follows: <script type="text/javascript"> <!-- var money; var name; //--> </script> We can also declare multiple variables with the same var keyword as follows: script type="text/javascript"> <!-- var money, name; //--> </script> 3. Explain the CSS Box Model in detail. All HTML elements can be considered as boxes. In CSS, the term "box model" is used when talking about design and layout. The CSS box model is essentially a box that wraps around HTML elements, and it consists of: margins, borders, padding, and the actual content. The box model allows us to place a border around elements and space elements in relation to other elements. The image below illustrates the box model:
  35. 35. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi Explanation of the different parts: Margin - Clears an area around the border. The margin does not have a background color, it is completely transparent Border - A border that goes around the padding and content. The border is affected by the background color of the box Padding - Clears an area around the content. The padding is affected by the background color of the box Content - The content of the box, where text and images appear 4. Describe the CSS Border Style Properties: The border-style property can have from one to four values. border-style: dotted solid double dashed; o top border is dotted o right border is solid o bottom border is double o left border is dashed border-style: dotted solid double; o top border is dotted o right and left borders are solid o bottom border is double border-style: dotted solid; o top and bottom borders are dotted o right and left borders are solid border-style: dotted;
  36. 36. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi o all four borders are dotted 5. Explain CSS Text Properties? Text Color -The color property is used to set the color of the text. The color can be specified by: Name – a color name, like “red” RGB – an RGB value, like “rgb (255, 0, 0)” Hex – a hex value, like “#ff0000” -The default color for a page is defined in the body selector. Text Alignment -The text-align property is used to set the horizontal alignment of a text. -Text can be centered, or aligned to the left or right, or justified. -When text-align is set to “justify”, each line is stretched so that every line has equal width, and the left and right margins are straight (like in magazines and newspapers). Text Decoration -The text-decoration property is used to set or remove decorations from text. -The text-decoration property is mostly used to remove underlines from links for design purposes: Text Transformation -The text-transform property is used to specify uppercase and lowercase letters in a text. It can be used to turn everything into uppercase or lowercase letters, or capitalize the first letter of each word. Text Indentation -The text-indentation property is used to specify the indentation of the first line of a text. 6. Explain in details about CSS. CSS stands for Cascading Style Sheets. Styles define how to display HTML elements. Styles were added to HTML 4.0 to solve a problem. External Style Sheets can save a lot of work. External Style Sheets are stored in CSS files. CSS Syntax A CSS rule has two main parts: a selector, and one or more declarations:
  37. 37. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi The selector is normally the HTML element you want to style. Each declaration consists of a property and a value. The property is the style attribute you want to change. Each property has a value. CSS Example A CSS declaration always ends with a semicolon, and declaration groups are surrounded by curly brackets: p {color:red;text-align:center;} To make the CSS more readable, you can put one declaration on each line, like this: Example p { color:red; text-align:center; } CSS Comments Comments are used to explain your code, and may help you when you edit the source code at a later date. Comments are ignored by browsers. A CSS comment begins with "/*", and ends with "*/", like this: /*This is a comment*/ p { text-align:center; /*This is another comment*/ color:black; font-family:arial; } CSS Id and Class The id and class Selectors In addition to setting a style for a HTML element, CSS allows you to specify your own selectors called "id" and "class". The id Selector The id selector is used to specify a style for a single, unique element. The id selector uses the id attribute of the HTML element, and is defined with a "#". The style rule below will be applied to the element with id="para1":
  38. 38. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi Example #para1 { text-align:center; color:red; } The class Selector The class selector is used to specify a style for a group of elements. Unlike the id selector, the class selector is most often used on several elements. This allows you to set a particular style for many HTML elements with the same class. The class selector uses the HTML class attribute, and is defined with a "." In the example below, all HTML elements with class="center" will be center-aligned: Example .center {text-align:center;} In the example below, all p elements with class="center" will be center-aligned: Example p.center {text-align:center;} CSS How To... When a browser reads a style sheet, it will format the document according to it. Three Ways to Insert CSS There are three ways of inserting a style sheet: External style sheet Internal style sheet Inline style External Style Sheet An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can change the look of an entire Web site by changing one file. Each page must link to the style sheet using the <link> tag. The <link> tag goes inside the head section: <head> <link rel="stylesheet" type="text/css" href="mystyle.css" /> </head> An external style sheet can be written in any text editor. The file should not contain any html tags. Your style sheet should be saved with a .css extension. An example of a style sheet file is shown below:
  39. 39. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi hr {color:sienna;} p {margin-left:20px;} body {background-image:url("images/back40.gif");} Do not leave spaces between the property value and the unit (such as margin-left:20 px). Correct way: margin-left:20px Internal Style Sheet An internal style sheet should be used when a single document has a unique style. You define internal styles in the head section of an HTML page, by using the <style> tag, like this: <head> <style type="text/css"> hr {color:sienna;} p {margin-left:20px;} body {background-image:url("images/back40.gif");} </style> </head> Inline Styles An inline style loses many of the advantages of style sheets by mixing content with presentation. To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example shows how to change the color and the left margin of a paragraph: <p style="color:sienna;margin-left:20px">This is a paragraph.</p> Multiple Style Sheets If some properties have been set for the same selector in different style sheets, the values will be inherited from the more specific style sheet. For example, an external style sheet has these properties for the h3 selector: h3 { color:red; text-align:left; font-size:8pt; } And an internal style sheet has these properties for the h3 selector: h3 { text-align:right; font-size:20pt; } If the page with the internal style sheet also links to the external style sheet the properties for h3 will be:
  40. 40. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi color:red; text-align:right; font-size:20pt; The color is inherited from the external style sheet and the text-alignment and the font-size is replaced by the internal style sheet. Multiple Styles Will Cascade into One Styles can be specified: inside an HTML element inside the head section of an HTML page in an external CSS file Tip: Even multiple external style sheets can be referenced inside a single HTML document. Cascading order Generally speaking we can say that all the styles will "cascade" into a new "virtual" style sheet by the following rules, where number four has the highest priority: Browser default External style sheet Internal style sheet (in the head section) Inline style (inside an HTML element) 7. Explain about JavaScript. JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as Internet Explorer, Firefox, Chrome, Opera, and Safari. JavaScript was designed to add interactivity to HTML pages. JavaScript is a scripting language. A scripting language is a lightweight programming language. JavaScript is usually embedded directly into HTML pages. JavaScript is an interpreted language. Everyone can use JavaScript without purchasing a license. Java and JavaScript are two completely different languages in both concept and design. Java (developed by Sun Microsystems) is a powerful and much more complex programming language - in the same category as C and C++. JavaScript gives HTML designers a programming tool - HTML authors are normally not programmers, but JavaScript is a scripting language with a very simple syntax! Almost anyone can put small "snippets" of code into their HTML pages. JavaScript can react to events - A JavaScript can be set to execute when something happens, like when a page has finished loading or when a user clicks on an HTML element. JavaScript can read and write HTML elements - A JavaScript can read and change the content of an HTML element JavaScript can be used to validate data - A JavaScript can be used to validate form data before it is submitted to a server. This saves the server from extra processing. JavaScript can be used to detect the visitor's browser - A JavaScript can be used to detect the visitor's
  41. 41. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi browser, and - depending on the browser - load another page specifically designed for that browser. JavaScript can be used to create cookies - A JavaScript can be used to store and retrieve information on the visitor's computer JavaScript = ECMAScript JavaScript is an implementation of the ECMAScript language standard. ECMA-262 is the official JavaScript standard. JavaScript was invented by Brendan Eich at Netscape (with Navigator 2.0), and has appeared in all browsers since 1996. The official standardization was adopted by the ECMA organization (an industry standardization association) in 1997. The ECMA standard (called ECMAScript-262) was approved as an international ISO (ISO/IEC 16262) standard in 1998. The development is still in progress. JavaScript How To The HTML <script> tag is used to insert a JavaScript into an HTML page. Writing to The HTML Document The example below writes a <p> element with current date information to the HTML document: Example <html> <body> <h1>My First Web Page</h1> <script type="text/javascript"> document.write("<p>" + Date() + "</p>"); </script> </body> </html> Note: Try to avoid using document.write() in real life JavaScript code. The entire HTML page will be overwritten if document.write() is used inside a function, or after the page is loaded. However, document.write() is an easy way to demonstrate JavaScript output in a tutorial. Changing HTML Elements The example below writes the current date into an existing <p> element: Example <html> <body> <h1>My First Web Page</h1> <p id="demo"></p> <script type="text/javascript"> document.getElementById("demo").innerHTML=Date();
  42. 42. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi </script> </body> </html> Note: To manipulate HTML elements JavaScript uses the DOM method getElementById(). This method accesses the element with the specified id. Examples Explained To insert a JavaScript into an HTML page, use the <script> tag. Inside the <script> tag use the type attribute to define the scripting language. The <script> and </script> tells where the JavaScript starts and ends: <html> <body> <h1>My First Web Page</h1> <p id="demo">This is a paragraph.</p> <script type="text/javascript"> ... some JavaScript code ... </script> </body> </html> The lines between the <script> and </script> contain the JavaScript and are executed by the browser. In this case the browser will replace the content of the HTML element with id="demo", with the current date: <html> <body> <h1>My First Web Page</h1> <p id="demo">This is a paragraph.</p> <script type="text/javascript"> document.getElementById("demo").innerHTML=Date(); </script> </body> </html> Without the <script> tag(s), the browser will treat "document.getElementById("demo").innerHTML=Date();" as pure text and just write it to the page: Some Browsers do Not Support JavaScript Browsers that do not support JavaScript will display JavaScript as page content. To prevent them from doing this, and as a part of the JavaScript standard, the HTML comment tag should be used to "hide" the JavaScript. Just add an HTML comment tag <!-- before the first JavaScript statement, and a --> (end of comment) after the last JavaScript statement, like this: <html>
  43. 43. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi <body> <script type="text/javascript"> <!-- document.getElementById("demo").innerHTML=Date(); //--> </script> </body> </html> The two forward slashes at the end of comment line (//) is the JavaScript comment symbol. This prevents JavaScript from executing the --> tag. JavaScript Where To JavaScripts can be put in the <body> and in the <head> sections of an HTML page. JavaScript in <body>. The example below writes the current date into an existing <p> element when the page loads: Example <html> <body> <h1>My First Web Page</h1> <p id="demo"></p> <script type="text/javascript"> document.getElementById("demo").innerHTML=Date(); </script> </body> </html> Note that the JavaScript is placed at the bottom of the page to make sure it is not executed before the <p> element is created. JavaScript Functions and Events JavaScripts in an HTML page will be executed when the page loads. This is not always what we want. Sometimes we want to execute a JavaScript when an event occurs, such as when a user clicks a button. When this is the case we can put the script inside a function. Events are normally used in combination with functions (like calling a function when an event occurs). You will learn more about JavaScript functions and events in later chapters. JavaScript in <head> The example below calls a function when a button is clicked: Example <html> <head> <script type="text/javascript"> function displayDate()
  44. 44. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi { document.getElementById("demo").innerHTML=Date(); } </script> </head> <body> <h1>My First Web Page</h1> <p id="demo"></p> <button type="button" onclick="displayDate()">Display Date</button> </body> </html> Scripts in <head> and <body> You can place an unlimited number of scripts in your document, and you can have scripts in both the body and the head section at the same time. It is a common practice to put all functions in the head section, or at the bottom of the page. This way they are all in one place and do not interfere with page content. Using an External JavaScript JavaScript can also be placed in external files. External JavaScript files often contain code to be used on several different web pages. External JavaScript files have the file extension .js. Note: External script cannot contain the <script></script> tags! To use an external script, point to the .js file in the "src" attribute of the <script> tag: Example <html> <head> <script type="text/javascript" src="xxx.js"></script> </head> <body> </body> </html> 8. Java script variables and operators. JavaScript Variables Variables are "containers" for storing information. JavaScript variables are used to hold values or expressions. A variable can have a short name, like x, or a more descriptive name, like carname. Rules for JavaScript variable names: • Variable names are case sensitive (y and Y are two different variables)
  45. 45. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi • Variable names must begin with a letter, the $ character, or the underscore character Example A variable's value can change during the execution of a script. You can refer to a variable by its name to display or change its value. Declaring (Creating) JavaScript Variables Creating variables in JavaScript is most often referred to as "declaring" variables. You declare JavaScript variables with the var keyword: var x; var carname; After the declaration shown above, the variables are empty (they have no values yet). However, you can also assign values to the variables when you declare them: var x=5; var carname="Volvo"; After the execution of the statements above, the variable x will hold the value 5, and carname will hold the value Volvo. Local JavaScript Variables A variable declared within a JavaScript function becomes LOCAL and can only be accessed within that function. (The variable has local scope). You can have local variables with the same name in different functions, because local variables are only recognized by the function in which they are declared. Local variables are deleted as soon as the function is completed. Global JavaScript Variables Variables declared outside a function become GLOBAL, and all scripts and functions on the web page can access it. Global variables are deleted when you close the page. Assigning Values to Undeclared JavaScript Variables If you assign values to variables that have not yet been declared, the variables will automatically be declared as global variables. These statements: x=5; carname="Volvo"; will declare the variables x and carname as global variables (if they don't already exist). JavaScript Arithmetic As with algebra, you can do arithmetic operations with JavaScript variables:
  46. 46. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi y=x-5; z=y+5; You will learn more about the operators that can be used in the next chapter of this tutorial. JavaScript Operators = is used to assign values. + is used to add values. The assignment operator = is used to assign values to JavaScript variables. The arithmetic operator + is used to add values together. y=5; z=2; x=y+z; The value of x, after the execution of the statements above, is 7. JavaScript Arithmetic Operators Arithmetic operators are used to perform arithmetic between variables and/or values. Given that y=5, the table below explains the arithmetic operators: Operator Description Example Result + Addition x=y+2 x=7 y=5 - Subtraction x=y-2 x=3 y=5 * Multiplication x=y*2 x=10 y=5 / Division x=y/2 x=2.5 y=5 % Modulus x=y%2x=1 y=5 ++ Increment x=++y x=6 y=6 x=y++ x=5 y=6 -- Decrement x=--y x=4 y=4 x=y-- x=5 y=4 JavaScript Assignment Operators Assignment operators are used to assign values to JavaScript variables. Given that x=10 and y=5, the table below explains the assignment operators: Operator Example Same As Result = x=y x=5 += x+=y x=x+y x=15 -= x-=y x=x-y x=5 *= x*=y x=x*y x=50 /= x/=y x=x/y x=2 %= x%=y x=x%y x=0 The + Operator Used on Strings The + operator can also be used to add string variables or text values together. To add two or more string variables together, use the + operator.
  47. 47. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi txt1="What a very"; txt2="nice day"; txt3=txt1+txt2; After the execution of the statements above, the variable txt3 contains "What a verynice day". To add a space between the two strings, insert a space into one of the strings: txt1="What a very "; txt2="nice day"; txt3=txt1+txt2; or insert a space into the expression: txt1="What a very"; txt2="nice day"; txt3=txt1+" "+txt2; After the execution of the statements above, the variable txt3 contains: "What a very nice day" Adding Strings and Numbers The rule is: If you add a number and a string, the result will be a string! Example x=5+5; document.write(x); x="5"+"5"; document.write(x); x=5+"5"; document.write(x); x="5"+5; document.write(x);
  48. 48. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi UNIT 3 1. Design a web page to detect the visitor’s browser name and version? <html> <body> <script type="text/javascript"> document.write("Browser CodeName: " + navigator.appCodeName); document.write("<br /><br />"); document.write("Browser Name: " + navigator.appName); document.write("<br /><br />"); document.write("Browser Version: " + navigator.appVersion); document.write("<br /><br />"); document.write("Cookies Enabled: " + navigator.cookieEnabled); document.write("<br /><br />"); document.write("Platform: " + navigator.platform); document.write("<br /><br />"); document.write("User-agent header: " + navigator.userAgent); </script> </body> </html> 2. Describe Cookies in detail. Cookies are used to store an ID for a shopping session with each subsequent connection, and can look up the current session ID and then use that ID to extract information about that session from a lookup table on the server machine. So, there would really be two tables: one that associates session IDs with user tables, and the user tables themselves that store user- specific data. For example, on the initial request a servlet could do something like the following: String sessionID = makeUniqueString(); HashMap sessionInfo = new HashMap(); HashMap globalTable = findTableStoringSessions(); globalTable.put(sessionID, sessionInfo); Cookie sessionCookie = new Cookie("JSESSIONID", sessionID); sessionCookie.setPath("/"); response.addCookie(sessionCookie); In later requests the server could use the global Table hash table to associate a session id from the jsessionid cookie with the session Info hash table of user-specific data. Using cookies in this manner is an excellent solution and is the most widely used approach for session handling. it is nice that Servlets have a higher-level API that handles all this plus the following tedious tasks: • Extracting the cookie that stores the session identifier from the other cookies (there may be many cookies, after all). • Determining when idle sessions have expired, and reclaiming them. • Associating the hash tables with each request.
  49. 49. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi • Generating the unique session identifiers. 3. Explain Sessions in detail? Sessions in servlets is straightforward and involves four basic steps. 1. Accessing the session object associated with the current request. -Call request.getSession to get an HttpSession object, which is a simple hash table for storing user-specific data. 2. Looking up information associated with a session. -Call getAttribute on the HttpSession object, cast the return value to the appropriate type, and check whether the result is null. 3. Storing information in a session. -Use setAttribute with a key and a value. 4. Discarding session data. -Call removeAttribute to discard a specific value. Calls invalidate to discard an entire session. Call logout to log the client out of the Web server and invalidate all sessions associated with that user. Accessing the Session Object Associated with the Current Request Session objects are of type HttpSession, but they are basically just hash tables that can store arbitrary user objects (each associated with a key). The HttpSession object can be implemented by calling the getSession method of HttpServletRequest, as below. HttpSession session = request.getSession(); 4. Explain URL Rewriting? URL Rewriting: -URL rewriting is another way to support anonymous session tracking. ie,If the browser does not support cookies, URL rewriting provides with another session tracking alternative. -With URL rewriting, every local URL the user might click on is dynamically modified, or rewritten, to include extra information. -The extra information can be in the form of extra path information, added parameters, or some custom, server-specific URL change. -Due to the limited space available in rewriting a URL, the extra information is usually limited to a unique session ID. Example:
  50. 50. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi For example, the following URLs have been rewritten to pass the session ID 123: http://server:port/servlet/Rewritten original http://server:port/servlet/Rewritten/123 extra path information http://server:port/servlet/Rewritten?sessionid=123 added parameter http://server:port/servlet/Rewritten;$sessionid$123 custom change Advantages: 1. URL rewriting works for all dynamically created documents servlet. 2. Custom URL rewriting can even work for static documents with the right server support. Disadvantages: 1. Using extra path information works on all servers, and it works as a target for forms that use both the GET and POST methods. It doesn't work well if a servlet has to use the extra path information as true path information. 2. Using an added parameter works on all servers too, but it fails as a target for forms that use the POST method, and it can cause parameter naming collisions. 3. Using a custom, server-specific change works under all conditions for servers that support the change. Unfortunately, it doesn't work at all for servers that don't support the change. 5. Explain about JavaScript global function? parseInt(x, [radix]) Parses any string "x" and returns the first valid number (integer) it encounters. If the first character in the string is not a number, white spaces, or a leading minus sign, parseInt() returns NaN instead. You can test for NaN using the isNaN() function below. parseInt() supports an optional 2nd "radix" parameter to specify the base of the number to be parsed (valid range is 2-36). Entering "10" would parse the number in the familiar decimal system, while "16" would be hexadecimal. Without this parameter present, parseInt() assumes any number that begins with "0x" to be radix 16, "0" to be radix 8, and any other number to be radix 10. Examples: parseInt("3 chances") //returns 3 parseInt("I have 3 computers") //returns NaN parseInt("17", 8) //returns 15 parseFloat(x) Parses any string "x" and returns the first valid floating point number it encounters. Use this function to extract numbers with decimals, for example. If the first character in the string is not a number, white spaces, or a leading minus sign, parseFloat() returns NaN instead. You can test for NaN using the isNaN() function below. Example: parseFloat("-3.98 points") //returns -3.98
  51. 51. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi 6. Explain in detail about DOM. The DOM is a W3C (World Wide Web Consortium) standard. The DOM defines a standard for accessing documents like HTML and XML: "The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document." The DOM is separated into 3 different parts / levels: • Core DOM - standard model for any structured document • XML DOM - standard model for XML documents • HTML DOM - standard model for HTML documents. The DOM defines the objects and properties of all document elements, and the methods (interface) to access them. What is the XML DOM? The XML DOM defines the objects and properties of all XML elements, and the methods (interface) to access them. What is the HTML DOM? The HTML DOM is: A standard object model for HTML. A standard programming interface for HTML. Platform- and language-independent. The HTML DOM defines the objects and properties of all HTML elements, and the methods (interface) to access them. In other words: The HTML DOM is a standard for how to get, change, add, or delete HTML elements. DOM Nodes According to the DOM, everything in an HTML document is a node. The DOM says: The entire document is a document node. Every HTML element is an element node. The texts in the HTML elements are text nodes. Every HTML attribute is an attribute node. Comments are comment nodes DOM Example Look at the following HTML document: <html> <head> <title>DOM Tutorial</title> </head> <body> <h1>DOM Lesson one</h1> <p>Hello world!</p> </body> </html> The root node in the HTML above is <html>. All other nodes in the document are contained within <html>.
  52. 52. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi The <html> node has two child nodes; <head> and <body>. The <head> node holds a <title> node. The <body> node holds a <h1> and <p> node. Text is Always Stored in Text Nodes A common error in DOM processing is to expect an element node to contain text. However, the text of an element node is stored in a text node. In this example: <title>DOM Tutorial</title>, the element node <title>, holds a text node with the value "DOM Tutorial". However, in the HTML DOM the value of the text node can be accessed by the innerHTML property. The HTML DOM Node Tree The HTML DOM views an HTML document as a tree-structure. The tree structure is called a node-tree. All nodes can be accessed through the tree. Their contents can be modified or deleted, and new elements can be created. The node tree below shows the set of nodes, and the connections between them. The tree starts at the root node and branches out to the text nodes at the lowest level of the tree: Node Parents, Children, and Siblings The nodes in the node tree have a hierarchical relationship to each other. The terms parent, child, and sibling are used to describe the relationships. Parent nodes have children. Children on the same level are called siblings (brothers or sisters). In a node tree, the top node is called the root. Every node, except the root, has exactly one parent node. A node can have any number of children. A leaf is a node with no children. Siblings are nodes with the same parent. The following image illustrates a part of the node tree and the relationship between the nodes:
  53. 53. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi Look at the following HTML fragment: <html> <head> <title>DOM Tutorial</title> </head> <body> <h1>DOM Lesson one</h1> <p>Hello world!</p> </body> </html> From the HTML above: The <html> node has no parent node; it is the root node. The parent node of the <head> and <body> nodes is the <html> node. The parent node of the "Hello world!" text node is the <p> node and: The <html> node has two child nodes; <head> and <body> The <head> node has one child node; the <title> node The <title> node also has one child node; the text node "DOM Tutorial" The <h1> and <p> nodes are siblings, and both child nodes of <body> First Child - Last Child From the HTML above: The <head> element is the first child of the <html> element, and the <body> element is the last child of the <html> element. The <h1> element is the first child of the <body> element, and the <p> element is the last child of the <body> element 7. Explain in details about Servlet with example. A Servlet is a java based server side web technology. As the name implies, it serves a client request and receives a response from the server. Technically speaking a Servlet is a Java class
  54. 54. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi in Java EE that conforms to the Java Servlet API, a protocol by which a Java class may respond to requests. They are not tied to a specific client-server protocol, but are most often used with the HTTP protocol. Therefore, the word "Servlet" is often used in the meaning of "HTTP Servlet".[2] Thus, a software developer may use a servlet to add dynamic content to a Web server using the Java platform. The generated content is commonly HTML, but may be other data such as XML. Servlets are the Java counterpart to non-Java dynamic Web content technologies such as CGI and ASP.NET. Servlets can maintain state in session variables across many server transactions by using HTTP cookies, or URL rewriting. To deploy and run a Servlet, a Web container must be used. A Web container (also known as a Servlet container) is essentially the component of a Web server that interacts with the servlets. The Web container is responsible for managing the lifecycle of servlets, mapping a URL to a particular servlet and ensuring that the URL requester has the correct access rights. The servlet API, contained in the Java package hierarchy javax.servlet, defines the expected interactions of the Web container and a servlet. A Servlet is an object that receives a request and generates a response based on that request. The basic servlet package defines Java objects to represent servlet requests and responses, as well as objects to reflect the servlet's configuration parameters and execution environment. The package javax.servlet.http defines HTTP-specific subclasses of the generic servlet elements, including session management objects that track multiple requests and responses between the Web server and a client. Servlets may be packaged in a WAR file as a Web application. Servlets can be generated automatically from JavaServer Pages (JSP) by the JavaServer Pages compiler. The difference between Servlets and JSP is that Servlets typically embed HTML inside Java code, while JSPs embed Java code in HTML. While the direct usage of Servlets to generate HTML (as shown in the example below) has become rare, the higher level MVC web framework in Java EE (JSF) still explicitly uses the Servlet technology for the low level request/response handling via the FacesServlet. A somewhat older usage is to use servlets in conjunction with JSPs in a pattern called "Model 2", which is a flavor of the model-view-controller pattern. A servlet is a Java component that can be plugged into a Java- enabled web server to provide custom services. These services can include: New features Runtime changes to content Runtime changes to presentation New standard protocols (such as FTP) New custom protocols Advantages over CGI The advantages of using Servlets are their fast performance and ease of use combined with more power over traditional CGI (Common Gateway Interface). Traditional CGI scripts written in Java have a number of disadvantages when it comes to performance: When an HTTP request is made, a new process is created for each call of the CGI script. This overhead of process creation can be very system-intensive, especially when the script does relatively fast operations. Thus, process creation will take more time than CGI script execution. Java Servlets solve this, as a Servlet is not a separate process. Each request to be
  55. 55. IT63 WEB TECHNOLOGY L.A.ANTO GRACIOUS, Lect/IT Marthandam College of Engineering and Technology Kuttakuzhi handled by a Servlet is handled by a separate Java thread within the Web server process, omitting separate process forking by the HTTP daemon. Simultaneous CGI request causes the CGI script to be copied and loaded into memory as many times as there are requests. However, with Servlets, there are the same amount of threads as requests, but there will only be one copy of the Servlet class created in memory that stays there also between requests. Only a single instance answers all requests concurrently. This reduces memory usage and makes the management of persistent data easy. A Servlet can be run by a Servlet engine in a restrictive environment, called a sandbox. This is similar to an applet that runs in the sandbox of the Web browser. This makes a restrictive use of potentially harmful Servlets possible. Life cycle of a Servlet During initialization stage of the Servlet life cycle, the web container initializes the Servlet instance by calling the init() method. The container passes an object implementing the ServletConfig interface via the init() method. This configuration object allows the Servlet to access name-value initialization parameters from the web application. After initialization, the Servlet can service client requests. Each request is serviced in its own separate thread. The Web container calls the service() method of the Servlet for every request. The service() method determines the kind of request being made and dispatches it to an appropriate method to handle the request. The developer of the Servlet must provide an implementation for these methods. If a request for a method that is not implemented by the Servlet is made, the method of the parent class is called, typically resulting in an error being returned to the requester. Finally, the Web container calls the destroy() method that takes the Servlet out of service. The destroy() method, like init(), is called only once in the lifecycle of a Servlet. Three methods are central to the life cycle of a Servlet. These are init( ), service( ), and destroy( ). They are implemented by every Servlet and are invoked at specific times by the server. Let us consider a typical user scenario to understand when these methods are called. Assume that a user enters a Uniform Resource Locator (URL) to a web browser. • The browser then generates an HTTP request for this URL. • This request is then sent to the appropriate server. • The HTTP request is received by the web server. • The server maps this request to a particular Servlet. • The Servlet is dynamically retrieved and loaded into the address space of the server. • The server invokes the init() method of the Servlet. • This method is invoked only when the Servlet is first loaded into memory. • It is possible to pass initialization parameters to the Servlet so it may configure itself. • The server invokes the service() method of the Servlet. • This method is called to process the HTTP request.

×