JSP Instructions


JSP

JavaServer Pages are intended to separate programming code from the way web pages are displayed. If this approach is followed, web designers can incorporate programming logic easily with minimal extra skills needed. Although this was the intent, it is not strictly enforced. It is up to you to manage you your JSP website effectively. You should not have lots of Java code in your JSP pages.

A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format, such as HTML, SVG, WML, and XML; and JSP elements, which construct dynamic content.

Here is a simple sample jsp file, today.jsp:

# 1:  <html>
# 2:  <head>
# 3:  <title>Date Example</title>
# 4:  </head>
# 5:
# 6:  <body>
# 7:  <%@ page language="java" %>
# 8:  <%@ page import="java.util.*" %>
# 9:  <%@ page import="java.text.*" %>
#10:  <P>Today's date is really really: <%= DateFormat.getDateInstance().format(new Date()) %></P>
#11:
#12:  </body>
#13:  </html>

1 Declarations

A JSP declaration is used to declare variables and methods in a page's scripting language. The syntax for a declaration is as follows: 

<%! scripting language declaration %>

When the scripting language is the Java programming language, variables and methods in JSP declarations become declarations in the JSP page's servlet class.

2 page Directives

Lines 7-9 contain page directives. These tell the JSP container information about how the page should be interpreted. The below table show examples of some page directives ( from Harms JSP, Serlets, and MySQL 2001 pages 81-82) are as follows:

extends=¡±classname¡±

import=¡±importlist¡±

session=¡±true|false¡±

buffer=¡±none|sizekb¡±

autoFlush=¡±True|False¡±

isThreadSafe=¡±True|False¡±

info=¡±info_text¡±

errorPage=¡±error_url¡±

isErrorPage=¡±true|false¡±

contentType=¡±ctinfo¡±

Two other directives are include and taglib directives.

             Example: <%@ include file="relativeURLspec" %>

             Example: <%@taglib uri= "tagLibraryURI" prefix="tagPrefix" %>

3 Scriptlets

Scripts (with the form of <% ... %> ) are Java code that execute in a page, which retrieve the value of the locale request parameter, iterate over a collection of locale names, and conditionally insert HTML text into the output. 

4 Expressions 

Expressions (with the form of <%= ... %>) insert the value of the locale name into the response. For example, the line 10 in the today.jsp file is contains embedded Java, a JSP action. It is a request for the date and is executed whenever the page is visited. It is java code. 

5 Applets

You can include an applet or JavaBeans component in a JSP page by using the jsp:plugin element. This element generates HTML that contains the appropriate client-browser-dependent constructs (<object> or <embed>) that will result in the download of the Java Plug-in software (if required) and client-side component and subsequent execution of any client-side component. The syntax for the jsp:plugin element is as follows:

<jsp:plugin 
   type="bean|applet" 
   code="objectCode
   codebase="objectCodebase
   { align="alignment" } 
   { archive="archiveList" } 
   { height="height" } 
   { hspace="hspace" } 
   { jreversion="jreversion" } 
   { name="componentName" } 
   { vspace="vspace" } 
   { width="width" } 
   { nspluginurl="url" } 
   { iepluginurl="url" } > 
   { <jsp:params> 
      { <jsp:param name="paramName" value="paramValue" /> }+
   </jsp:params> } 
   { <jsp:fallback> arbitrary_text </jsp:fallback> } 
</jsp:plugin>

If you want to go further into JSP Technology, please visit the JSP Website for tutorial, documentation and source code.

¡¡

  Go Back To TA Page   


Course Webpage | JSP | Servlet | Apache Ant | Apache Jakarta Tomcat | FAQ | Contact Us