6
Web
Development with Java
and can detect and correct mistakes in the written format. For example, a para-
graph tag in HTML is a paired tag and most browsers will render paragraphs
correctly, even if the closing paragraph tag is missing. The reason is that paragraph
tags cannot be nested one inside the other, so when a browser encounters a new
tag before seeing the closing
for
the current paragraph, the browser
inserts a closing
and then begins the new paragraph. However, if an XML
interpreter were used to read the same HTML fi le with the missing
tag, the
interpreter would report an error instead of continuing to parse the fi le. It is better
to code all the tags that are defi ned for a well-formed HTML document, than to
rely on browsers to fi ll in the missing details.
Standard Tags
The HTML specifi cation defi nes a group of standard tags
that control the structure
of the HTML document. These tags will contain plain text and other tags.
html code
The
html
tags enclose all the other tags and text in the document.
browser command tags
The
head
tags enclose tags that inform the browser about how to display the
entire page. These control how the page appears in the browser, but do not
contain any content for the page. This paired tag belongs within the paired
tags.
body tags
section within the paired
tags.
3. The
DOCTYPE
and
meta
tags are required if the page is to be validated by W3C
for correct HTML syntax. Go to http://www.w3.org to access the HTML validator.
There is no excuse for a web page to contain errors. With the use of the validation
tool at http://www.w3.org, all HTML pages should be validated
to ensure that they
contain all the basic tags.
Layout versus Style
There are two different types of information that are contained in each HTML
page: layout and style. The basic layout is covered in this chapter; advanced layout
and style are covered in Chapter Six. Style information contains things like the
colours and font for the page. The recommended way to handle style and layout
is to place all the layout tags in the HTML page and to place all the style informa-
tion in a separate fi le, called a style sheet.
For the interested student, the HTML
and style information from Chapter Six can be read at any time.
There are different DOCTYPE statements that can be used for HTML pages:
strict and transitional. The strict one is the recommended one, since it enforces
the rule that all style information be contained in a separate fi le. All pages for this
book will use the strict DOCTYPE for HTML pages.
8
Web Development with Java
Word Wrap and White Space
Most of us are used to typing text in a word processor and letting the program deter-
mine where the line breaks belong. This is know as
word wrap
.
The only time that
we are required to hit the enter key is when we want to start a new paragraph.
Browsers will use word wrap to display text, even if the enter key is pressed.
Browsers will treat a new line character, a tab character and multiple spaces as
a single space. In order to insert a new line, tab or multiple spaces in an HTML
page, markup must be used: if it is not plain text, then it must be placed
in markup.
Browsers take word wrap one step further. Browsers
will compress all consecu-
tive white space characters into a single space character. The common white space
characters are the space, the tab and the new line character. If there are fi ve spaces
at the start of a line, they will be compressed into one space.
The following listing contains a web page that has a poem.
<
Do'stlaringiz bilan baham: