|
JSP Elements
Part:
1
2
3
4
Syntactic Elements of a JSP Page
There are two types of data in a JSP page:
- Template Data: The static part, anything that will be copied directly to the response by the JSP server.
- JSP Elements: The dynamic part, anything that will be translated and executed by the JSP server.
There are three types of JSP elements:
Directive Element: A JSP element that provides global information for the translation phase.
There are two ways to write a directive element:
<%@ directive_name attribute=value ... %>
Action Element: A JSP element that provides information for the execution phase.
<action_name attribute=value ...>action_body</action_name>
<action_name attribute=value .../>
Scripting Element: A JSP element that provides embedded Java statements. There are
three types of scripting elements:
Declaration Element: A JSP element that provides the embedded Java declaration statements
to be inserted into the Servlet class.
<%! Java decalaration statements %>
Scriptlet Element: A JSP element that provides the embedded Java statements
to be executed as part of the service method of the Servlet class. There are two ways
to write a scriptlet element:
<% Java statements %>
Expression Element: A JSP element that provides the embedded Java expressions
to be evaluated as part of the service method of the Servlet class. There are two ways
to write an express element:
<% Java expressoins %>
Writing JSP Pages in XML Format
JSP pages can also be written in XML format. To do this, you have to use the
XML version of the syntaxes for directive elements, declaration, scriptlet and
expression elements:
<jsp:directive.directive_name attribute=value .../>
<jsp:declaration> Java decalaration statements </jsp:declaration>
<jsp:scriptlet> Java statements </jsp:scriptlet>
<jsp:expression> Java expressions </jsp:expression>
You also have to create a "jsp:root" element. Here is my "Hello world!" example
in XML format:
<?xml version="1.0"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2">
<!-- hello_xml.jsp
Copyright (c) 2002 by Dr. Herong Yang
-->
<html><body>
<jsp:scriptlet>out.println("Hello world!");</jsp:scriptlet>
</body></html>
</jsp:root>
Then open this JSP page with IE, what you will see is this:
- <html>
<body>Hello world!</body>
</html>
(Continued on next part...)
Part:
1
2
3
4
|