JSP Tutorial Summary
JSPs have many of the servlet advantages while solving some of the troublesome issues associated with servlets. JSPs allow HTML professionals and Java professionals to work in the same file and syntax (maybe the same tools) to assemble the web pages. Unlike servlets, no configuration of JSPs is required. JSPs are not registered or mapped in the web.xml file.
A JSP is stored in plain text format with a .jsp extension. JSPs are stored with the HTML pages of your Web site. The Web container takes a JSP and turns it into a servlet, generating and compiling the Java code for you.
Aside from HTML, there are three types of JSP structures: scripting elements, directives and tags. In addition, as of the JSP 2.0 specification, there is an additional expression language that Java JSP developers must know.
There are three script elements each with identifying syntax.
- Scriptlets – <% %> or <jsp:scriptlet> </jsp:scriptlet>
- Expressions – <%= %> or <jsp:expression> </jsp:expression>
- Declarations – <%! %> or <jsp:declaration> </jsp:declaration>
JSPs come with a set of predefined variables called implicit objects.
- Directives provide instructions to the JSP engine on how to process the page.
- Conventionally, directives are specified at the top of a JSP page before any other JSP tags.
- There are only a few types of directives: page, include and taglib.
- The Page directive defines attributes and characteristics of a JSP page.
- The page import directive allows imports to be added to the generated servlet.
- The page session directive allows the automatically generated session to be turned off.
- The page directives of buffer and autoflush determine the size of the response buffer and whether it should be automatically flushed when full.
- Page directives of isErrorPage and errorPage provide the preferred way of handling exceptions in JSPs.
- The include directive instructs the JSP compiler to include a complete file into the current JSP file.
- The Include directive can be used to break a single JSP into multiple files.
Copyright (c) 2008-2013. Intertech, Inc. All Rights Reserved. This information is to be used exclusively as an online learning aid. Any attempts to copy, reproduce, or use for training is strictly prohibited.