Books
in black and white
Main menu
Home About us Share a book
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

Java Server your visual Blueprint to Design Dynamic Content - Whitehead P.

Whitehead P. Java Server your visual Blueprint to Design Dynamic Content - Wiley Publishing, 2001. - 133 p.
Download (direct link): yourtodesigningdynamic2001.pdf
Previous << 1 .. 25 26 27 28 29 30 < 31 > 32 33 34 35 36 37 .. 117 >> Next

You must first create the file you want to include. The file can contain plain text or HTML code, such as a table, header or footer. If the file contains plain text, you can save the file with the .txt extension. If the file contains HTML code, you can save it with the .html extension.
The include file should not contain any JavaServer Pages code. The Web server will ignore any JavaServer Pages code included in the file.
To include a file in a JSP page, you add an include statement to the page. The include statement must be enclosed between the <%@ opening delimiter and the %> closing delimiter. The filename specified in the include statement must be enclosed in quotation marks. The filename must be a fixed value, such as "footer.html".
You cannot use a variable that represents the name of a file in an include statement.
If you change the code in the file, all of the JSP pages that include the file will be updated. You may have to clear the Web server's buffer before your JSP pages will display the changes made to the file. For information about clearing the Web server's buffer, see page 92.
USING THE INCLUDE DIRECTIVE
JS\ Untitled - Notepad
File Edit Search Help
<h1>Welcome to ny Web site</h1>|
^|0Jx]

Z] images 2] jsp
22 META-INF ] servlets Z]WEB-INF
e
<t= -
File name: | welcome, html
Save as type: | Tent Documents
~3
a
CREATE A FILE TO INCLUDE
-D In a text editor, create the file you want to include in several JSP pages.
Untitled - Notepad
File Edit Search Help
J
Save the file.
Note: If the file contains plain text, save the file with the .txt extension. If the file contains HTML code, save the file with the .html extension.
<html>
<head>
<title>My Web Page</title> </head>
<body>
<%B include file="" %>|-
</body>
</html>
INCLUDE A FILE
D Display the code for the JSP page in which you want to include a file.
H Between the <body> and < /body> tags, type <%@ include file="" %>.
76
GETTING STARTED WITH JAVASERVER PAGES
3
The include directive allows you to include a file that is stored in the same directory as the JSP page that includes the file or in a subdirectory of that directory. In this example, the JSP page is stored in a directory called test and the footer.html file is stored in a subdirectory called test/pages.
Example:
<% include file="pages/footer.html" %>
You can also include a file that is located in the parent directory of the directory that stores the JSP page. To do so, you use the double dot notation to represent the name of the parent directory. In this example, the JSP page is instructed to look for the welcome.html file in the parent directory.
Example:
<% include file="../welcome.html" %>
Using the include directive allows you to break code into manageable sections and then include the code in JSP pages as needed. Each include file should contain code specific to only one task. If you create a file that contains code for many tasks, the JSP pages may not use all the code and the Web server's resources will be wasted.
m
File ?dit Search Help
J File Edit View Favorites Tools Help
<html>
<head>
J <i=i Back ? ^ J ffl a Search [j] Favorites ^History | ^ Qf Q JPt
<title>My Web Page</title>
</head>
<body>
Welcome to my Web site
<%e include file='jwelcone^htri3]" %>
>
</body>
</html>
f] Done
between the quotation marks, type the name of the file you want to include.
? Save the page with the .jsp extension and then display the JSP page in a Web browser.
I The Web browser displays the result of using the include directive.
77
JSP
INTRODUCTION TO IMPLICIT OBJECTS
Implicit objects are created automatically when a Web server processes a JSP page. The available implicit objects include application, config, exception, out, page, pageContext, request, response and session. Each object is used to perform a specific task, such as handling errors,
sending text generated by a JSP page to a Web browser or interpreting information submitted by a form on a Web page.
Implicit objects are available for use in every JSP page you create. You do not have to write code that imports or instantiates an implicit object.
Object Scope
The scope of an object determines where the object can be accessed in an application. For example, the session object has session scope, which means that the object can be accessed by any JSP page processed during a session. Most implicit objects have page scope. When an object has page scope, the object can be accessed only in the JSP page in which the object was created. You can access implicit objects only from within scriptlets or expressions on a JSP page. Implicit objects are not available for use in directives, such as the page directive.
OBJECT: SCOPE: |
application application
config page
exception page
out page
page page
pageContext page
request request
response page
session session
Class Files
Since JSP pages use the underlying servlet technology of the Web server, implicit objects are usually derived from class files that are part of the servlet packages. For more information about implicit objects and the servlet packages, you can consult the Java SDK documentation.
Previous << 1 .. 25 26 27 28 29 30 < 31 > 32 33 34 35 36 37 .. 117 >> Next