InfoCenter Home >
4: Developing applications >
4.2: Building Web applications >
4.2.2: Developing JSP files >
4.2.2.3: Overview of JSP file content

4.2.2.3: Overview of JSP file content

JSP files have the extension .jsp. A JSP file contains any combination of the following items. Click an item to learn about its syntax. To learn how to put it all together, see the Related information for examples, samples, and additional syntax references.

JSP syntax

Syntax format Details
Directives Use JSP directives (enclosed within <%@ and %>) to specify:
  • Scripting language being used
  • Interfaces a servlet implements
  • Classes a servlet extends
  • Packages a servlet imports
  • MIME type of the generated response
   See Sun's JSP Syntax Reference for JSP 1.1 syntax descriptions and examples.
Class-wide variable and method declarations Use the <%! declaration(s) %> syntax to declare class-wide variables and class-wide methods for the servlet class.
Inline Java code (scriptlets), enclosed within <% and %> You can embed any valid Java language code inline within a JSP file between the <% and %> tags. Such embedded code is called a scriptlet. If you do not specify the method directive, the generated code becomes the body of the service method.

An advantage of embedding Java coding inline in JSP files is that the servlet does not have to be compiled in advance, and placed on the server. This makes it easier to quickly test servlet coding.

Variable text, specified using IBM extensions for variable data (JSP .91 or JSP 1.0) or Java expressions enclosed within <%= and %> The IBM extensions are the more user-friendly approach to putting variable fields on your HTML pages.

A second method for adding variable data is to specify a Java language expression that is resolved when the JSP file is processed. Use the JSP expression tags <%= and %>. The expression is evaluated, converted into a string, and displayed. Primitive types, such as int and float, are automatically converted to string representation.

<BEAN> tag Use the <BEAN> tag to create an instance of a bean that will be accessed elsewhere within the JSP file. Then use JSP tags to access the bean.
JSP tags for database access (JSP .91) or (JSP 1.1) The IBM extensions make it easy for non-programmers to create Web pages that access databases.

HTML tags

A JSP file can contain any valid HTML tags. View article 0.70: What is HTML? for more information on HTML. Refer to your favorite HTML reference for a description of HTML tags.

<SERVLET> tags

Using the <SERVLET> tag is one method for embedding a servlet within a JSP file.

NCSA tags

You might have legacy SHTML files that contain NCSA tags for server-side includes. If the IBM WebSphere Application Server Version 3.5 supports the NCSA tags in your SHTML files, you can convert the SHTML files to JSP files and retain the NCSA tags.

Go to previous article: Compiling JSP 1.0 files as a batch Go to next article: JSP  syntax: JSP directives

 

 
Go to previous article: Compiling JSP 1.0 files as a batch Go to next article: JSP  syntax: JSP directives