This tutorial teaches JSP by progressing from very simple examples to complex examples. Advanced learners may want to do a quick review of the introductory. JSP – This technology is used to create dynamic web application same like Servlet technology Before learning of this tutorial you must be knowledge of Servlet. This tutorial introduces the fundamentals of JavaServer Pages (JSP) technology version and provides an update to the original tutorial.
|Published (Last):||19 April 2006|
|PDF File Size:||16.45 Mb|
|ePub File Size:||5.44 Mb|
|Price:||Free* [*Free Regsitration Required]|
Fundamentally, this means that a JSP document must be well formed, meaning that each start tag must have a corresponding end tag and that the document must have only one root element. Those elements that are not compliant are summarized in Table ispx with the equivalent elements in XML syntax. The standard syntax version is as follows:. As you can see, a number of constructs that are legal in standard syntax have been changed to comply with XML syntax:. With only these few small changes, when you save the file with a.
It explains how to use XML namespaces to declare tag libraries, include directives, and create static and dynamic content in your JSP tugorial.
It also describes jsp: In standard syntax, the taglib directive declares tag libraries used in a JSP page. Here is an example of a taglib directive:. This syntax is not allowed in JSP documents. To declare a tag library in a JSP document, you use the xmlns attribute, which is used to declare namespaces according to the XML standard:.
The URN of the form urn: This capability has many advantages:. In this way, all elements within the books element have access to these tag libraries. In this way, the tag library referenced by the jsp prefix is available only to the jsp: Similarly, the tag library referenced by the c prefix is only available to the c: Scoping the namespaces also allows you to override the prefix. For example, in another part of the page, you could bind the c prefix to a different namespace or tag library.
In contrast, the jsp prefix must always be bound to the JSP namespace: The directives themselves do not appear in the XML output.
There are three directives: The taglib directive is covered in the preceding section. This element must be a child of the root element.
All the attributes are optional. Except for the import and pageEncoding attributes, there can be only one instance of each attribute in an element, but an element ttuorial contain more than one attribute. An example of a page directive is one that tells the JSP container to load an error tutorisl when it throws an exception.
You can add this error page directive tutprial the books. If there is an error when you try to execute the page perhaps when you want to see the XML output of books. You can place this element anywhere in a document. This is done to simplify validation. Suppose that you want to use an include directive to add a JSP document containing magazine data inside the JSP document containing the books data. To do this, you can add the following include directive to books.
The output generated from books. The output of this example will not be well-formed XML because of the two root elements, so the client might refuse to process it. However, it is still a legal JSP document. The container detects tutoriap page you are including and parses it as either a standard syntax JSP page or a JSP document and then places it into the XML view for validation.
This section explains how to represent static text and dynamic content in a JSP document. If you use jsp: For example, consider this example using XML tags:. The whitespace characters are x20x9xD ,and xA.
You can also use jsp: Therefore, if you need to nest a tag inside jsp: The following example requires CDATA wrappers around the blockquote start and end tags because the blockquote element is not well formed. This is because the blockquote element overlaps with other elements in the example. Just like JSP pages, JSP documents can generate dynamic content using expressions language EL expressions, scripting elements, standard actions, and custom tags.
As shown in this snippet from books. The EL expressions access the JavaBeans component, which in turn retrieves the data from the database:. When using the expression language in your JSP documents, you must substitute alternative notation for some of the operators so that they will not be interpreted as XML markup. Table enumerates the more common operators and their alternative syntax in JSP documents.
You can also use EL expressions with jsp: This example could be used to generate an HTML header tag with a lang attribute:.
The name attribute identifies the generated tag’s name. The body of the jsp: The output of this example jsp: The only exception is a scriptlet expression used to specify a request-time attribute value. This element has no attributes, and its body is the program fragment that constitutes the scriptlet.
The root element of the books. The version attribute is the only required attribute of the jsp: However, suppose that you want to generate two XML documents from books.
Introduction to JavaServer Pages
To do this, you can use this jsp: Notice in this example that jsp: For more information on the document type declaration, see Referencing the DTD.
The XML declaration and document type declaration that are declared by the jsp: Instead, the container simply directs them to the request output.
To illustrate this, here is an example of specifying a document type declaration with jsp: Specifying the document type declaration in the jsp: Table shows all the jsp: They are all optional, but some attributes depend on other attributes occurring in the same jsp: The rest of this section explains more about using jsp: This declaration is the default XML declaration. Therefore, the default XML declaration is generated in the output.
A document type declaration DTD defines the structural rules for the XML document in which the document type declaration occurs. In fact, the books example does not include one. This section shows you how to use the jsp: It also shows you how to enter the document type declaration manually into books.
As shown in Tablethe jsp: Suppose that you want to reference a DTD, called books.
DTDfrom the output of the books. The DTD would look like this:. The JSP container will automatically place the resulting document type declaration before the start of the output of the JSP document. Note that the JSP container will not interpret anything provided by jsp: It only generates the document type declaration in the XML request output. To see the XML tuttorial, run http: DTD and the jsp: When using some browsers, you might need to view the source of the page to actually see the output.
Directing the document type declaration to output without interpreting it is useful in situations when another system receiving the output expects to see jsox.
For example, two companies that do business via a web service might use a standard DTD, against which any XML content exchanged between the companies is validated by the consumer of the content. For the JSP container to validate tutprial. DTDyou must manually include the document type declaration in the books. However, you must add definitions for all tags in your DTD, including jepx for standard elements and custom tags, such as jsp: The taglib directives have been removed.
Tag libraries are now declared using XML namespaces, as shown in the html element. The include directive has been changed to the XML-compliant jsp: Japx plain URI that is a unique identifier for the tag library.
Introduction to JavaServer Pages
It allows you to use xmlns to declare other namespaces and not just tag libraries. When you want to identify the document as a JSP document to the JSP container without having to add any configuration attributes to the deployment descriptor or tutorizl the document with a. A value of true or yes omits the XML declaration.
A value of false or no generates an XML tktorial. Can be specified only if doctype-system is specified.