Using JavaServer pages with web transactions

When you save a VGUIRecord source file, a default JSP file is created, based on the fields in the VGUIRecord part. You can edit this default JSP to change its appearance or the data displayed on it. More information on JSP technology is available atJavaServer Pages (JSP) technology

JavaServer Pages (JSP files) are ASCII files that have a .jsp suffix and contain a mixture of HTML tags and JSP syntax. A web application server transforms a JSP file into a Java™ servlet by a process known as page compilation.

Scriptlets

Pieces of Java code called scriptlets can be inserted into JSP files. Scriptlets can be placed anywhere in the JSP source. At run time, the Java code in the scriptlet runs on the server side, but the Java code itself is not included with the HTML sent to the browser. Methods specific to UI record beans are covered in UI record bean API.

The following code shows a simple scriptlet:

<% if (x == 1) {out.println(EMPNO.getLabel())}; %>

The Java code in a scriptlet can add to the HTML by printing a string to the out PrintWriter object. This out object is created and made available to the scriptlet as part of the page compilation process of the JSP. The out object accepts only strings. If you need to print something other than a string type, you must first convert that type to a string.

There are three ways to print to the out object.

<% out.print(string_value); %>
This scriptlet adds the string string_value to the HTML code at the location of the scriptlet.
<% out.println(string_value); %>
This scriptlet adds the string string_value to the HTML code at the location of the scriptlet and then adds a carriage control character. Adding the carriage control character starts the next HTML code on the next line, which can increase the readability of the source code. This carriage return does not affect the appearance of the HTML in the browser, and it does not have the effect of the HTML <br> tag.
<% string_value %>
This scriptlet is equivalent to <% out.print(string_value); %>.

In this way, scriptlets let you access data in the VGUIRecord and use that data on the page. For specific methods for accessing a UI record bean, see UI record bean API.

Bean tags

The JSP file created to go along with the VGUIRecord references a UI record bean. This UI record bean gives the scriptlets in the JSP access to the data in the VGUIRecord. The JSP file references this bean with the <jsp:useBean> tag.

For example, the following code references a bean to be used in a JSP file:

<jsp:useBean id="referenceName" 
class="beanClassName" 
type="interfaceName" 
scope="beanScope" />
referenceName
The name of the bean. Other scriptlets in the JSP file can use this bean by referring to its name as defined in the <jsp:useBean> tag.
beanClassName
The fully qualified class name of the bean, such as java.lang.String.
interfaceName
A interface implemented by a bean. This attribute is optional.
beanScope
The scope of the bean. Valid values are:
session
The bean is stored in the HttpSession object.
request
The bean is stored in theHttpServletRequest object.
page
The bean is stored in the JSP page context.
application
The bean is stored in the servlet context.

Directives

The JSP file can also include JSP directives. Two of these directives are significant when working with web transactions:

The import directive lets you add Java import statements. These import statements apply to any scriptlet in the JSP. Java import statements are a shorthand to save you from having to type out the fully qualified name of the package everywhere when referring to elements inside it.

Add the following import directive to each JSP file created to work with a VGUIRecord:

<%@ page import = "com.ibm.vgj.uibean.VGDataElement" %>

The errorPage directive specifies a web page to forward the browser to in response to an uncaught exception. For example, if a UI record JSP specifies an incorrect array index in a call to the UI record bean, the JSP specified in the errorPage directive handles the error.

Do not specify CSOERRORUIR.jsp in the errorPage directive, even though CSOERRORUIR.jsp is the error page that you customize to report on TCP/IP communication problems and on problems internal to a web transaction. If you want all errors to be presented by CSOERRORUIR,jsp, specify errorPage="vagen1error.jsp".

The following example shows an errorPage directive:

<%@ page errorPage="jspName.jsp" %>

Feedback