0% found this document useful (0 votes)
88 views5 pages

Is Shown in 16 PT Black Color)

Cascading Style Sheets (CSS) allow separation of document content from design and formatting, making websites easier to maintain. CSS specifies simple formatting instructions that can be applied to text elements like fonts, colors, spacing and more. This improves accessibility, load times, and consistency across pages by defining styles in a single CSS file rather than inline HTML tags. JavaScript is a scripting language used to make websites interactive by adding features like form validation, animations, and dynamic content. It is placed within <script> tags in an HTML page and allows variables, functions, and control structures to be written and used in a browser.

Uploaded by

Sathish A Avn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views5 pages

Is Shown in 16 PT Black Color)

Cascading Style Sheets (CSS) allow separation of document content from design and formatting, making websites easier to maintain. CSS specifies simple formatting instructions that can be applied to text elements like fonts, colors, spacing and more. This improves accessibility, load times, and consistency across pages by defining styles in a single CSS file rather than inline HTML tags. JavaScript is a scripting language used to make websites interactive by adding features like form validation, animations, and dynamic content. It is placed within <script> tags in an HTML page and allows variables, functions, and control structures to be written and used in a browser.

Uploaded by

Sathish A Avn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Cascading Style Sheet: One of the most important accepts of HTML is capability

HTML LANGUAGE: HTML stands for Hyper Text Markup Language. Hyper: HTML
of separating the presentation and content. A style is simple set of instructions
allows non-linear access to information. Anyone can go anywhere on the World
that can be applied to a piece of text CSS makes the website maintain Easier
Wide Web, whenever he/she wants to. Text: The HTML code is simple text.
Cascading Style Sheets are formal specifications described by W3C. A Style is
Markup: To indicate to the browser, the structure and format of the information,
simply a set of formatting instructions that can be applied to piece of text. CSS
tags are used to mark the information, i.e. the data is marked. A markup
gave designers the ability to fully layout, position and define pages, without use
language is a set of markup tags Language: It is a language. The purpose of the
of tables, and any other hacks. Using CSS, a designer could define the fonts each
tags is to describe page content Html is the major language of the World Wide
tag would use, its color, its margin, and many other properties. HTML tags were
Web. Web pages are written in Html, which enables us to bring together text,
originally designed to present the content of a document in a web Browser.
pictures, sounds and links all in one place.
Every tag has a pre defined style/presentation Ex: <h1> Hello </h1>( “Hello Text
Structure of HTML Document is shown in 16 pt black color)
<html>, <head>, <title>Title of page</title>, </head>, <body>, <b>This text is Why do we use CSS? Imagine you've just designed a two hundred page web site
bold</b> , </body>, </html> for a client (or maybe for yourself) but at the last minute your client (or you)
<HTML>: This tag should be the first one in your html document. This is to tell decides the font is a little two small or the typeface should be serif instead of
the browser that it is receiving an HTML text and start working to display that sans-serif? This is where you need to develop your website with CSS!! That's just
page. This tag identifies the document as an html document. one file to upload. CSS makes web site maintenance easier. Cascading style
To tell the browser, that your html document has ended, you use </HTML>. sheets have a side effect of improving page load time for your site. With CSS, the
<TITLE>: This tag is used to specify the title of the document and appears in the style sheet is downloaded once and cached, and every page beyond your first
title bar (top left) of the browser window. Use </TITLE> to close the tag. page is shorter and sweeter. Every page that uses your style sheet is also more
<BODY>: This tag specifies the main content of a document. All the content that consistent, because it is derived from an identical style.
has to be shown on the page, should appear between the <BODY> and the
</BODY> tags. Cascading style sheets also improve accessibility. If someone has poor eyesight,
HTML Tags Headings: Headings are defined with the <h1> to <h6> tags. <h1> they can use the advanced feature of a web browser to define their own style.
defines the largest heading. <h6> defines the smallest heading. paragraphs: What is JavaScript? JavaScript is: JavaScript is a lightweight, interpreted
Paragraphs are defined with the <p> tag. Don’t Forget the Closing Tag You might programming language Designed for creating network-centric applications
have noticed that paragraphs can be written without end tags </p>Line Breaks: Complementary to and integrated with Java Complementary to and integrated
The <br> tag is used when you want to break a line, but don't want to start a new with HTML Open and cross-platform JavaScript Syntax: A JavaScript consists of
paragraph. The <br> tag forces a line break wherever you place it. <p>This<br> is JavaScript statements that are placed within the <script>... </script> HTML tags
a para<br>graph with line breaks</p><br> or <br /> More and more often you in a web page. You can place the <script> tag containing your JavaScript
will see the <br> tag written like this: <br /> Because the <br> tag has no end tag anywhere within you web page but it is preferred way to keep it within the
(or closing tag), it breaks one of the rules for future HTML (the XML based <head> tags. The <script>tag alerts the browser program to begin interpreting all
XHTML), namely that all elements must be closed. Writing it like <br /> is a future the text between these tags as a script. So simple syntax of your JavaScript will be
proof way of closing (or ending) the tag inside the opening tag, accepted by both as follows: <script ...> JavaScript code </script> The script tag takes two
HTML and XML. Comments in HTML: The comment tag is used to insert a important attributes Whitespace and Line Breaks: JavaScript ignores spaces,
comment in the HTML source code. A comment will be ignored by the browser. tabs, and newlines that appear in JavaScript programs. Because you can use
You can use comments to explain your code, which can help you when you edit spaces, tabs, and newlines freely in your program so you are free to format and
the source code at a later date. indent your programs in a neat and consistent way that makes the code easy to
Lists Lists are used to present information in an easy to read form. You can have read and understand. Semicolons are Optional: Simple statements in JavaScript
ordered lists, unordered lists as well as any combination of the two. Unordered are generally followed by a semicolon character, just as they are in C, C++, and
Lists An unordered list is a list of items. The list items are marked with bullets Java. JavaScript, however, allows you to omit this semicolon if your statements
(typically small black circles). An unordered list starts with the <ul> tag. Each list are each placed on a separate line. For example, the following code could be
item starts with the <li> tag. Inside a list item you can put paragraphs, line written without semicolons. <script language="javascript"
breaks, images, links, other lists, etc. LI is a tag that denotes a list item, which is type="text/javascript"><!--, var1 = 10 var2 = 20 , //--></script> But when
usually preceded by a bullet, a number or letter. The UL tag has an attribute formatted in a single line as follows, the semicolons are required: Case
called TYPE that can be set to any of circle: specifies a hollow bullet. disc: Sensitivity:JavaScript is a case-sensitive language. This means that language
specifies a round solid bullet. square: specifies a square bullet. Ordered Lists An keywords, variables, function names, and any other identifiers must always be
ordered list is also a list of items. The list items are marked with numbers. An typed with a consistent capitalization of letters. So identifiers Time, TIme and
ordered list starts with the <ol> tag. Each list item starts with the <li> tag. TIME will have different meanings in JavaScript. Comments in JavaScript:
To create a list that puts a number in front of every list item instead of bullets, JavaScript supports both C-style and C++-style comments, Thus: Any text
from the previous list, you only have to change the tag type from UL to OL between a // and the end of a line is treated as a comment and is ignored by
(Ordered List). The items will will be numbered starting from 1. START is an JavaScript. Any text between the characters /* and */ is treated as a comment.
attribute of Ordered Lists that can be used to specify the number assigned to the This may span multiple lines. JavaScript also recognizes the HTML comment
first item in the list. This number should be a positive integer. Nested Lists opening sequence <!--. JavaScript treats this as a single-line comment, just as it
One can have an Ordered List inside an Unordered List and vice versa. This can be does the // comment. JavaScript - Errors & Exceptions Handling There are three
achieved by putting the nested ordered (or unordered) list as a list member using types of errors in programming: (a) Syntax Errors and (b) Runtime Errors (c)
LI. Add the code on the next few slides, to a web document and view the result in Logical Errors: Syntax errors: Syntax errors, also called parsing errors, occur at
a browser. <HTML> Definition Lists Definition lists consist of pairs of values, the compile time for traditional programming languages and at interpret time for
first being the term to be defined, and the second being the definition of the JavaScript. For example, the following line causes a syntax error because it is
tem. missing a closing parenthesis: <script type="text/javascript">, <!-- ,
window.print(); //--> </script>, Logical errors: Logic errors can be the most
Frames With frames, you can display more than one HTML document in the difficult type of errors to track down. These errors are not the result of a syntax
same browser window. Each HTML document is called a frame, and each frame is or runtime error. Instead, they occur when you make a mistake in the logic that
independent of the others. The disadvantages of using frames are: The web drives your script and you do not get the result you expected. You cannot catch
developer must keep track of more HTML documents It is difficult to print the those errors, because it depends on your business requirement what type of
entire page Frames are used to break up the browser window and put the logic you want to put in your program. The try...catch...finally Statement: The
contents of two or more web pages on the same page. If you have a site that has latest versions of JavaScript added exception handling capabilities. JavaScript
a number of pages and you want the visitor to have the option to jump to any implements the try...catch...finally construct as well as the throw operator to
page of the site, no matter which page he is on, at that moment, you can put a handle exceptions. You can catch programmer-generated and runtime
page, which just has links to all the pages as, one of the frames. Such “navigation exceptions, but you cannot catch JavaScript syntax errors. Here is the
links frames” are widely used on the web. A web page that contains frames try...catch...finally block syntax The try block must be followed by either exactly
consists of a “master” html document, which defines the layout or the one catch block or one finally block (or one of both). When an exception occurs
arrangement of framed areas on the page. Create a web document with the in the try block, the exception is placed in e and the catch block is executed. The
following code and view it in a browser optional finally block executes unconditionally after try/catch. The throw
Statement: You can use throw statement to raise your built-in exceptions or your
customized exceptions. Later these exceptions can be captured and you can take
an appropriate action. Following is the example showing usage of throw
statement. The onerror() Method The onerror event handler was the first
feature to facilitate error handling for JavaScript. The errorevent is fired on the
window object whenever an exception occurs on the page.
Dynamic HTML with Java Script: DHTML in javascript can be obtained by the
following ways: Dynamic Style Sheets, The all Collection, Using the item() method SAX Parser: SAX (the Simple API for XML) is an event-based parser for xml
for more control, The styleSheets Collection, Dynamic Style Sheets Just recently, documents. The parser tells the application what is in the document by notifying
two technologies have been released for precise control of the layout and the application of a stream of parsing events. Application then processes those
positioning of elements on a page. Cascading Style Sheets : CSS gave designers events to act on data. SAX 1.0 was released on May 11, 1998. SAX is a common,
the ability to fully layout, position and define pages, without use of tables, and event-based API for parsing XML documents, developed as a collaborative
any other hacks., Using CSS, a designer could define the fonts each tag would project of the members of the XML-DEV discussion under the leadership of David
use, its color, its margin, and many other properties. Using JavaScript to Control Megginson. Why SAX? For applications that are not so XML-centric, an object-
Style Sheets With the release of the 4.0 browsers from Microsoft and Netscape, based interface is less appealing. Efficiency: lower level than object-based
finally comes the capability to script style sheets using scripting language such as interfaces. Event-based interface consumes fewer resources than an object-
JavaScript and VBScript. What are the Advantages? These new technologies based one. With an event-based interface, the application can start processing
enable us to do: Make the text on the page adjust its size to adapt to the user's the document as the parser is reading it.
browser size Create text rollover effects without the need for graphics Create an
Html based menu that can expand and collapse to show its contents Change text
properties on-the-fly without a full page refresh Fade in and fade out page Difference between SAX and DOM parsers SAX is event based and DOM is tree
elements Unlike CGI, the script handles everything on the client side, making the model. Event based means some kind of events happens to the node. Like when
web pages load quickly, thus enhancing the interactive experience. we click particular node then it will give all the sub nodes rather than loading all
the nodes at the same time. But in case of DOM parse it will load all the nodes
and makes the tree model. SAX is a stream-based processor. You only have a tiny
XML: Document type definition, XML Schemas, Document Object model, part in memory at any time and you "sniff" the XML stream as it passes. It uses
Presenting XML, Using XML Processors: DOM and SAX What is XML? XML stands almost no memory, but you can't do "DOM" stuff, like use xpath or traverse
for EXtensible Markup Language. XML is a markup language much like HTML. trees.DOM: You load the whole thing into memory - it's a massive memory hog.
XML was designed to carry data, not to display data. XML tags are not You can blow memory with even medium sized documents. But you can use
predefined. You must define your own tags. XML is designed to be self- xpath and traverse the tree etc Both SAX and DOM are used to parse the XML
document. Both have advantages and disadvantages and can be used in our
descriptive. XML is designed to transport and store data. XML is important to
programming depending on the situation. SAX: Parses node by node, Doesn’t
know, and very easy to learn. XML was created to structure, store, and transport store the XML in memory , We can’t insert or delete a node, SAX is an event
information. XML is now as important for the Web as HTML was to the based parser, SAX is a Simple API for XML, doesn’t preserve comments,SAX
foundation of the Web. XML is the most common tool for data transmissions generally runs a little faster than DOM DOM: Stores the entire XML document
between all sorts of applications. XML became a W3C Recommendation on into memory before processing, Occupies more memory,We can insert or delete
February 10, 1998. nodes, Traverse in any direction.,DOM is a tree model parser, Document Object
Model (DOM) API, Preserves comments, SAX generally runs a little faster than
DOM, If we need to find a node and doesn’t need to insert or delete we can go
The Difference between XML and HTML XML is not a replacement for HTML. with SAX itself otherwise DOM provided we have more memory....
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,
Advantages of Java Beans Software component architecture provides standard
while XML is about carrying information. HTML and XML look similar, because
they are both SGML languages (SGML = Standard Generalized Markup Language) mechanisms to deal withsoftware building blocks. The following list enumerates
Both HTML and XML use elements enclosed in tags (e.g. <body>This is an some of the specific benefitsthat Java technology provides for a component
element</body>) Both use tag attributes (e.g., <font face="Verdana" size="+1" developer: A Bean obtains all the benefits of Java’s “write-once, run-anywhere”
color="red">) Both use entities (&lt;,&gt;, &amp;, &quot;, &apos;) More paradigm. The properties, events, and methods of a Bean that are exposed to
precisely, HTML is defined in SGML , XML is a (very small) subset of SGML HTML anapplication builder tool can be controlled. A Bean may be designed to operate
is for humans HTML describes web pages, You don’t want to see error messages correctly in different locales, which makes ituseful in global markets. Auxiliary
about the web pages you visit, Browsers ignore and/or correct as many HTML
software can be provided to help a person configure a Bean.Thissoftware is only
errors as they can, so HTML is often sloppy , XML is for computers XML describes
data The rules are strict and errors are not allowed. In this way, XML is like a needed when the design-time parameters for that componentare being set. It
programming language Current versions of most browsers can display XML does not need to be included in the run-time environment. The configuration
However, browser support of XML is spotty at best settings of a Bean can be saved in persistent storage andrestored at a later time.
A Bean may register to receive events from other objects and can generate
events.
Document-Object-Model(DOM) The Document Object Model (DOM) is the
interface that allows programmatically accessing and manipulating the contents Web Servers A server is a computer that responds to requests from a client
of a web page or document. DOM is aobject-based, platform and language Typical requests: provide a web page, upload or download a file, send email A
independent standard object model for representing HTML or XML and related server is also the software that responds to these requests; a client could be the
formats. DOM is a tree-like structure implied by the abstract relationships browser or other software making these requests Typically, your little computer
defined by the programming interfaces The (DOM) is a platform and language is the client, and someone else’s big computer is the server However, any
neutral Application Programming Interface (API) that allows programs to access computer can be a server It is not unusual to have server software and client
and update the content, structure, and style of a document. DOM: What is it? software running on the same computer Apache Tomcat web server: Apache is a
DOM provides a structured, object-oriented representation of the individual very popular server 66% of the web sites on the Internet use Apache Apache is:
elements and content in a page with methods for retrieving and setting the Full-featured and extensible, Efficient, Robust, Secure (at least, more secure than
properties of the objects. Provides methods for adding and removing such other servers), Up to date with current standards, Open source, Free, A port is a
objects, allowing to create dynamic content. Provides an interface for dealing connection between a server and a client, Ports are identified by positive
with events, allowing capturing and responding to user or browser actions. integers, A port is a software notion, not a hardware notion, so there may be
Provides a foundation for developing querying, filtering, transformation, very many of them., A service is associated with a specific port, Typical port
rendering etc applications on top of DOM implementations numbers: Tomcat is the Servlet Engine than handles servlet requests for Apache,
Tomcat is a “helper application” for Apache, It’s best to think of Tomcat as a
DOM Parser: XML DOM defines a standard way for accessing and manipulating “servlet container”, Apache can handle many types of web services, Apache can
XML documents. The XML DOM views an XML document as a tree-structure. All be installed without Tomcat, Tomcat can be installed without Apache, It’s easier
elements can be accessed through the DOM tree. Their content (text and
to install Tomcat standalone than as part of Apache, By itself, Tomcat can handle
attributes) can be modified or deleted, and new elements can be created. The
elements, their text, and their attributes are all known as nodes. The HTML DOM web pages, servlets, and JSP, Apache and Tomcat are open source (and therefore
defines a standard way for accessing and manipulating HTML documents. All free)
HTML elements can be accessed through the HTML DOM. The XML DOM is: A
standard object model for XML A standard programming interface for XML
Platform- and language-independent A W3C standard
The XML DOM defines the objects and properties of all XML elements, and
the methods (interface) to access them.
In other words: The XML DOM is a standard for how to get, change, add, or
delete XML elements.
CGI Scripts CGI stands for “Common Gateway Interface” Client sends a request Servlet API There are two packages that contain the classes and interfaces that
to server , Server starts a CGI script, Script computes a result for server and quits, are required to build servlets. These are javax.servlet, javax.servlet.http., They
Server returns response to client, Another client sends a request, Server starts constitute the Servlet API. These packages are not part of the Java core packages
the CGI script again, They are not included in the Java Software Development Kit. You must download
Disadvantages of CGI In the early days of the Web, a server could dynamically Tomcat to obtain their functionality. The Servlet API has been in a process of
construct a page by creating a separate process to handle each client request. ongoing development and enhancement. The current servlet specification is
The process would open connections to one or more databases in order to obtain version is 2.3 The Servlet API is supported by most Web servers.
the necessary information. It communicated with the Web server via an interface
known as the Common Gateway Interface (CGI). CGI allowed the separate Javax.servlet Package The following are the interfaces Servlet: Declares life cycle
process to read data from the HTTP request and write data to the HTTP response. methods for a servlet. ServletConfig: Allows servlets to get initialization
A variety of different languages were used to build CGI programs. These included parameters. ServletContext:Enables servlets to log events and access
C, C++, and Perl. CGI suffered serious performance problems. It was expensive in information about their environment. ServletRequest: Used to read data from a
terms of processor and memory resources to create a separate process for each client request. ServletResponse: Used to write data to a client response.
client request. It was also expensive to open and close database connections for SingleThreadModel: Indicates that the servlet is threading safe. The following
each client request. The CGI programs were not platform-independent. are the Classes GenericServlet: Implements the Servlet and
ServletConfiginterfaces. ServletInputStream: Provides an input stream for
Web Servers A server is a computer that responds to requests from a client reading requests from a client. ServletOutputStream: Provides an output stream
Typical requests: provide a web page, upload or download a file, send email A for writing responses to a client. ServletException: Indicates a servlet error
server is also the software that responds to these requests; a client could be the occurred. UnavailableException: Indicates a servlet is unavailable.
browser or other software making these requests Typically, your little computer Servlet Interface methods All servlets must implement the Servlet interface. It
is the client, and someone else’s big computer is the server However, any declares the init ( ), service ( ), and destroy ( ) methods that are called by the
computer can be a server It is not unusual to have server software and client server during the life cycle of a servlet. A method is also provided that allows a
software running on the same computer servlet to obtain any initialization parameters. The methods defined by Servlet
methods. void destroy( ):Called when the servlet is unloaded. ServletConfig
Life Cycle of a Servlet Three methods are central to the life cycle of a servlet. init( getServletConfig ():Returns a ServletConfig object that contains any initialization
), service( ), destroy( ) They are implemented by every servlet and are invoked at parameters. String getServletInfo (): Returns a string describing the servlet. void
specific times by the server. Working of life cycle A user enters a Uniform service(ServletRequest req,ServletResponse res) throw
Resource Locator (URL) to a Web browser. The browser then generates an HTTP ServletException,IOException Called to process a request from a client. The
request for this URL. This request is then sent to the appropriate server. This request from the client can be read from req. The response to the client can be
HTTP request is received by the Web server. The server maps this request to a written to res. An exception is generated if a servlet or IO problem occurs. void
particular servlet. The servlet is dynamically retrieved and loaded into the init(ServletConfig sc) throws ServletException
address space of the server. The server invokes the init ( ) method of the servlet. Called when the servlet is initialized. Initialization parameters for the servlet can
This method is invoked only when the servlet is first loaded into memory. It is be obtained from sc. An Unavailable Exception should be thrown if the servlet
possible to pass initialization parameters to the servlet so it may configure itself. cannot be initialized.
The server invokes the service ( ) method of the servlet. This method iscalled to
process the HTTP request. You will see that it is possible for the servlet to read
data that has been provided in the HTTP request. It may also formulate an HTTP
response for the client.The servlet remains in the server’s address space and is Session Tracking HTTP is a stateless protocol. Each request is independent of the
available to process any other HTTP requests received from clients. The service ( previous one. However, in some applications, it is necessary to save state
) method is called for eachHTTP request. The server may decide to unload the information so that information can be collected from several interactions
servletfrom its memory. The algorithms by which this determination is made are between a browser and a server. Sessions provide such a mechanism. Number of
specific to each server. The server calls the destroy( )method to relinquish any problems that arise from the fact that HTTP is a "stateless" protocol. In
resources such as file handles that are allocated for the servlet. Important data particular, when you are doing on-line shopping, it is a real annoyance that the
may be saved to a persistent store. The memory allocated for the servlet and its Web server can't easily remember previous transactions. This makes applications
objects can then be garbage collected. Types of Servlets : Generic Servlet: A like shopping carts very problematic: when you add an entry to your cart, how
GenericServlet has a service () method to handle requests. It is protocol does the server know what's already in your cart? Even if servers did retain
independent. Http Servlet: The HttpServlet extends GenericServlet and adds contextual information, you'd still have problems with e-commerce. how does
support for HTTP protocol based methods like doGet(), doPost(), doHead() etc. It the server remember what you were buying? A session can be created via the
is protocol dependent. HttpServlet is a protocol dependent whereas getSession( ) method of HttpServletRequest. An HttpSession object is returned.
GenericServlet is protocol independent HttpServlet belongs to javax.servlet.http This object can store a set of bindings that associate names with objects. The
package .This is an abstract class which extends GenericServlet and implements setAttribute( ), getAttribute( ), getAttributeNames( ), and removeAttribute( )
java.io.Serializable A subclass of HttpServlet must override at least one method methods of HttpSession manage these bindings. It is important to note that
of doGet(), doPost(),doPut(), doDelete(), init(), destroy(), getServletInfo(). session state is shared among all the servlets that are associated with a
particular client
What is Session Tracking? HTTP is a stateless protocol. A stateless protocol does
not require the server to retain information or status about each user for the
duration of multiple requests. For example, when a web server is required to
customize the content of a web page for a user, the web application may have to
track the user's progress from page to page. A common solution is the use of
HTTP cookies. Other methods include server side sessions, hidden variables
(when the current page contains a form), and URL-rewriting using URI-encoded
parameters, e.g., Cookies, URL Rewriting, Hidden form fields.
Cookies A cookie is a piece of textual information Send by the Web server to the Why Use JSP? JavaServer Pages often serve the same purpose as programs
client browser Every time the browser visits the Web site again, the cookie is implemented using the Common Gateway Interface (CGI). But JSP offer several
sent unchanged back to the server A cookie is a keyed piece of data that is advantages in comparison with the CGI. Performance is significantly better
because JSP allows embedding Dynamic Elements in HTML Pages itself instead of
created by the server and stored by the client browser. Browsers maintain their
having a separate CGI files.
own list of unique cookies. This makes cookies a very viable solution for session JSP are always compiled before it's processed by the server unlike CGI/Perl which
The Servlet API provides built-in support for cookies. It does this through the use requires the server to load an interpreter and the target script each time the
of the Cookie class and the HttpServletResponse.addCookie () and page is requested. JavaServer Pages are built on top of the Java Servlets API, so
HttpServletRequest. getCookies() methods. The problem is privacy, not security. like Servlets; JSP also has access to all the powerful Enterprise Java APIs,
Don't put sensitive info in cookies Cookie definition: including JDBC, JNDI, EJB, JAXP etc. JSP pages can be used in combination with
Web server sends a cookie name and value to a browser and later can read them servlets that handle the business logic, the model supported by Java servlet
template engines. Finally, JSP is an integral part of J2EE, a complete platform for
back from the browser. The process: – Servlet sends a cookie with its response to
enterprise class applications. This means that JSP can play a part in the simplest
the client. – The client saves the cookie. – The client returns a cookie back with applications to the most complex and demanding.
subsequent requests (depends on some rules). Anatomy of a JSP Page: A JSP page is simply a regular web page with JSP
Benefits of Cookies : Identifying a user during an e-commerce session. This type elements for generating the parts of the page that differ for each request, We
ofshort-term tracking is so important that another API is layered on top of can say that JSP page has two components : JSP Elements, Template Data
cookies for this purpose. Many online stores use a “shopping cart” metaphor in
which users select items, add them to their shopping carts, and then continue
shopping. Since the HTTP connection is usually closed after each page is sent, JSP Application Design with MVC JSP technology can play a part in everything
when a user selects a new item to add to the cart, how does the store know that from the simplest web application, such as an online phone list or an employee
it is the same user who put the previous item in the cart? Cookies solve this vacation planner, to full-fledged enterprise applications, such as a human
problem Remembering usernames and passwords: Cookies let a user log in to a resource application or a sophisticated online shopping site. How large a part JSP
site automatically, providing a significant convenience for users of unshared plays differs in each case, of course. In this section, we introduce a design model
suitable for both simple and complex applications called Model-View-Controller
computers.Cookies is a good alternative for low-security sites. When a user
(MVC). MVC was first described by Xerox in a number of papers published in the
registers, a cookie containing a unique user ID is sent to him. When the client late 1980s. The key point of using MVC is to separate components into three
reconnects at a later date, the user ID is returned automatically, the server looks distinct units: the Model, the View, and the Controller. In a server application, we
it up, determines it belongs to a registered user that chose autologin, and commonly classify the parts of the application as: business logic, presentation,
permits access without an explicit username and password. Customizing sites: and request processing. Business logic (Model)is the term used for the
Sites can use cookies to remember userpreferences. Many “portal” sites let you manipulation of an application's data, i.e., customer, product, and order
information. Presentation (View)refers to how the application is displayed to
customize the look of the main page. They might let you pick which weather
the user, i.e., the position, font, and size. And finally, Request processing
report you want to see, what stock symbols should be displayed and how search (Controller)is what ties the business logic and presentation parts together. In
results should be displayed Focusing advertising: Cookies let the site remember MVC terms, the Model corresponds to business logic and data, the View to the
which topicsinterest certain users and show advertisements relevant to those presentation logic, and the Controller to the request processing.
interests. Most advertiser-funded Web sites charge their advertisers much more
for displaying “directed” (or “focused”) ads than for displaying “random” ads. For JSP Implicit Objects JSP Implicit Objects are the Java objects that the JSP
example, if you go to a search engine and do a search on “Java Servlets,” the Container makes available to evelopers in each page and developer can call
them directly without being explicitly declared. JSP Implicit Objects are also
search site can charge an advertiser much more for showing you an ad for a
called pre-defined variables. JSP supports nine Implicit Objects which are listed
servlet development environment than for an ad for an online travel agent below: Request, Response, Out, Session, Application, Config, Pagecontext, Page,
specializing in Indonesia. Some Problems with Cookies Cookies are not a serious Exception
security threat. Cookies are never interpreted or executed in any way and thus The request Object: The request object is an instance of a
cannot be used to insert viruses or attack your system. Browsers generally only javax.servlet.http.HttpServletRequest object. Each time a client requests a page
accept 20 cookies per site and 300 cookies total, and since browsers can limit the JSP engine creates a new object to represent that request. The request
each cookie to 4 kilobytes, Cookies cannot be used to fill up someone’s disk or object provides methods to get HTTP header information including form data,
cookies, HTTP methods etc. The response Object:
launch other denial-of-service attacks. Sending Cookies to the Client 1. Creating
The response object is an instance of a javax.servlet.http.HttpServletResponse
a Cookie object: You call the Cookie constructor with a cookie name and a cookie object. Just as the server creates the request object, it also creates an object to
value, both of which are strings. Cookie c = new Cookie ("name", "value"); 2. represent the response to the client. The response object also defines the
Setting the maximum age: If you want the browser to store the cookie on disk interfaces that deal with creating new HTTP headers. Through this object the JSP
instead of just keeping it in memory, you use setMaxAge to specify how long (in programmer can add new cookies or date stamps, HTTP status codes etc. The out
seconds) the cookie should be valid. c.setMaxAge Object: The out implicit object is an instance of a javax.servlet.jsp.JspWriter
object and is used to send content in a response. The session Object: The
(60*60*24*7); // One week 3. Placing the Cookie into the HTTP response
session object is an instance of javax.servlet.http.HttpSession and behaves
headers. : You use response.addCookie(c) to accomplish this. If you forget this exactly the same way that session objects behave under Java Servlets. The
step, no cookie is sent to the browser! application Object: The application object is direct wrapper around the
Introduction to JSP: The Problem with Servlet. The Anatomy of a JSP Page, JSP ServletContext object for the generated Servlet and in reality an instance of a
Processing. JSP Application Design with MVC Setting Up and JSP Environment: javax.servlet.ServletContext object.The config Object: The config object is an
Installing the Java Software Development Kit, Tomcat Server & Testing Tomcat. instantiation of javax.servlet.ServletConfig and is a direct wrapper around the
Overview: Java Server Pages (JSP) is a technology for developing web pages that ServletConfig object for the generated servlet. The pageContext Object: The
support dynamic content which helps developers insert java code in HTML pages pageContext object is an instance of a javax.servlet.jsp.PageContext object. The
by making use of special JSP tags, most of which start with <% and end with %>. pageContext object is used to represent the entire JSP page.
A Java Server Pages component is a type of Java servlet that is designed to fulfill
the role of a user interface for a Java web application. Web developers write
JSPs as text files that combine HTML or XHTML code, XML elements, and
embedded JSP actions and commands. Using JSP, you can collect input from
users through web page forms, present records from a database or another
source, and create web pages dynamically. JSP tags can be used for a variety of
purposes, such as retrieving information from a database or registering user
preferences, accessing JavaBeans components, passing control between pages
and sharing information between requests, pages etc.Problems with Servlets: It
is a common fact that servlets incorporate both the processing logic and
presentation logic, thereby requiring the developer to have immense knowledge
in java programming as well as HTML programming to develop a web application,
which is not always possible. Secondly, every chance in the presentation logic
(the look and feel) of the application requires the servlet programmer to update
the servlet code and recompile it. And finally, web page development tools do
not directly support servlets when designing application interface. Even if such
tools are used, then the generated HTML code must be manually inserted into
the servlet, through the println method of PrintWriter object which is very
Introduction to JDBC : JDBC is an API that allows you to store, retrieve, and
manipulate data in virtually any data source, and to manipulate the data
structures. Although the JDBC 4.0 Specification proposal has been drafted, we
will cover the current version, JDBC 3.0, which is included in J2SE 1.4. This
section explains the JDBC object model and the most important classes and
interfaces, to enable you to develop database-based servlet and JSP applications.
Here are the steps required to access data in a database:
Load the JDBC database driver., Create a connection., Create a statement.,
Create a resultset, if you expect the database server to send back some data.
Type 1 JDBC Driver: JDBC-ODBC Bridge driver The Type 1 driver translates all
JDBC calls into ODBC calls and sends them to the ODBC driver. ODBC is a generic
API. The JDBC-ODBC Bridge driver is recommended only for experimental use or
when no other alternative is available.
Type 1: JDBC-ODBC Bridge Advantage The JDBC-ODBC Bridge allows access to
almost any database, since the database's ODBC drivers are already available.
Disadvantages Since the Bridge driver is not written fully in Java, Type 1 drivers
are not portable. A performance issue is seen as a JDBC call goes through the
bridge to the ODBC driver, then to the database, and this applies even in the
reverse process. They are the slowest of all driver types. The client system
requires the ODBC Installation to use the driver.
Not good for the Web.

Introduction to struts framework A framework for writing Web-based


applications in Java that supports the Model-View-Controller (MVC) architecture.
Struts is deployed as JSP pages using special tags from the Struts tag library,
which includes routines for building forms, HTML rendering, storing and
retrieving data and business logic. The Struts Framework is a standard for
developing well-architected Web applications. It has the following features: Open
source, Based on the Model-View-Controller (MVC) design paradigm, distinctly
separating all three levels: Model: application state View: presentation of data
(JSP, HTML) Controller: routing of the application flow Implements the JSP Model
2 Architecture Stores application routing information and request mapping in a
single core file, struts-config.xml. The Struts Framework, itself, only fills in the
View and Controller layers. The Model layer is left to the developer.Three key
components to the Struts framework: 1)A "request" handler 2) A "response"
handler 3) A tag library
Benefits of struts framework: We have number of benefits in using struts
framework for developing web applications in java, before we look into the
benefits of struts you need to remember that all the benefits of the MVC
approach and Model 2 development model are available when using struts. For
example MVC model 2 provides a clear separation between the presentation
logic from the request handling code(usingJava Servlets, Plain Java Classes
and JSP Scriplet etc) is also one of the benefits of Struts.
Web application developed using Struts framework is easier to develop
understand and maintain. 1) Struts is open source , which allows us to download
the source code and modify that code according to our requirement that
supports user extensions 2) The other important advantage of struts being open
source is that its code is exposed to the developers and this enable fast
development and maintence cycle; as a result we can expect fast response from
struts team in fixing the bugs and response to the new requirements in the
market.The basic purpose of the Java Servlets in struts is to handle requests
made by the client or by web browsers. In struts JavaServerPages (JSP) are used
to design the dynamic web pages. In struts, servlets helps to route request which
has been made by the web browsers to the appropriate ServerPage. The use of
servlet as a router helps to make the web applications easier to design, create,
and maintain. Struts are purely based on the Model- View- Contoller (MVC)
design pattern. It is one of the best and most well developed design patterns in
use. By using the MVC architecture we break the processing in three sections
named Model, the View, and the Controller. Below we are describing the working
of struts. As we all are well aware of the fact that each application we develop
has a deployment descriptor i.e. WEB-INF/web.xml. This is the file which the
container reads. This file has all the configuration information which we have
defined for our web application. The configuration information includes the index
file, the default welcome page, the mapping of our servlets including path and
the extension name, any init parameters, information related to the context
elements.
In the file WEB-INF/web.xml of struts application we need to configure the Struts
ActionServlet which handles the entire request made by the web browsers to a
given mapping. ActionServlet is the central component of the Struts controller.
This servlet extends the HttpServlet. This servlet basically performs two
important things. First is: When the container gets start, it reads the Struts
Configuration files and loads it into memory in the init() method. You will know
more about the Struts Configuration files below. Second point is: It intercepts
the HTTP request in thedoGet() and doPost() method and handles it
appropriately.

You might also like