Previous Next Contents Index


HttpServletRequest2 interface

This interface extends the standard javax.servlet.http.HttpServletRequest interface.

Although anyone developing an application for NAS can use HttpServletRequest2, this interface is typically used in components generated by Netscape Application Builder. HttpServletRequest2 provides methods for handling servlet errors, as well as providing additional support for servlets.

One method in particular, the getAppLogic( ) method, is useful to developers outside the NAB environment. Through the getAppLogic( ) method, the HttpServletRequest2 interface supports servlet access to AppLogics, allowing applications to call methods on AppLogics.

Package
com.netscape.server.servlet.extension

Methods
Method
Description
convertITemplateDataToResultSet( )
Creates a ResultSet wrapper for an ITemplateData object.
dispatchAction( )
Calls a method corresponding to a form-action in a servlet.
formActionHandlerExists( )
Determines whether the servlet has form-actions defined on it.
getAppLogic( )
Returns a handle to the AppLogic instance (ServletRunner) that served this request.
getDefaultTemplate( )
Retrieves the name of the file that handles output.
getErrorCodes( )
Retrieves a vector of error codes.
getErrorMsgs( )
Retrieves a vector of error messages.
getErrorVars( )
Retrieves a vector of error variables.
getHttpSessionBean( )
Retrieves an instance of a session object that is defined by the programmer.
getServletErrorHandler( )
Retrieves the object that handles validation errors.
setDefaultTemplate( )
Sets the default template to another file.
setServletErrorHandler( )
Sets the IServletErrorHandler that is used to process errors.
validate( )
Validates input parameters and session variables.

Related Topics
IServletErrorHandler interface,

Taking Advantage of NAS Features

convertITemplateDataToResultSet( )
Creates a ResultSet wrapper for an ITemplateData object.

Syntax
public static ResultSet convertITemplateDataToResultSet(
	String groupName,
	ITemplateData templateData)

groupName. The group name of the specified ITemplateData.

templateData. The ITemplateData to be wrapped.

Usage
The convertITemplateDataToResultSet( ) method takes an ITemplateData object and wraps it so that it conforms to the specifications of a JDBC ResultSet object.

Use this method only if you have HTML templates that were developed for a previous version of NAS, and you want to run them in the JSP engine.

Rules
Hierarchical ITemplateData objects are not supported, so do not specify one as a parameter.

Return Value
A ResultSet object.

dispatchAction( )
Calls a method corresponding to a form-action in a servlet.

Syntax
public abstract int dispatchAction(
	HttpServletResponse response,
	HttpServlet servlet) throws ServletException, IOException

response. The HttpServletResponse object.

servlet. The HttpServlet object on which the actionHandler will be invoked.

Usage
Use this method to handle form actions. For example, if an application user presses a button in a web page form, the dispatchAction( ) method calls the button handler method that corresponds to the specific form and action.

The form, action, and corresponding handler are defined by the servlet developer in the servlet's NTV file.

Tip
It is useful to call formActionHandlerExists( ) before dispatchAction( ) to determine whether the servlet has form-actions defined on it.

Return Value
Returns NO_ERROR (a value of 0) if the method succeeds; otherwise, returns ERROR_NO_DISPATCH_HANDLER. (a value of 1), which means that dispatching cannot be done. If an event handler exists and is called, then dispatchAction( ) returns that handler's return value.

Related Topics
formActionHandlerExists( )

formActionHandlerExists( )
Determines whether the servlet has form-actions defined on it.

Syntax
public abstract boolean formActionHandlerExists()
Usage
This method accesses the NTV list and, by doing so, determines whether the servlet has form-actions defined on it. This information is useful to the dispatchAction( ) method, so you typically call formActionHandlerExists( ) before dispatchAction( ).

Tip
This method appears in code generated by Netscape Application Builder. If you are not using NAB, you typically will not need to call this method.

Return Value
Returns true if form-actions are defined on the servlet.

Related Topics
dispatchAction( )

getAppLogic( )
Returns a handle to the AppLogic instance (ServletRunner) that served this request.

Syntax
public abstract AppLogic getAppLogic()
Usage
Use this method when you want to access the ServletRunner AppLogic. The getAppLogic( ) method lets developers call any AppLogic methods.

Tip
Deprecated AppLogic methods should not be called. For example, calling methods that stream data, such as streamResult( ), streamResultBinary( ), and streamResultHeader( ), may conflict with similar methods in HTTPResponse that also stream data.

Return Value
An AppLogic object.

Related Topics
AppLogic class

getDefaultTemplate( )
Retrieves the name of the file that handles output.

Syntax
public abstract String getDefaultTemplate()
Usage
In some cases, a servlet's NTV file indicates a default servlet or JSP file that handles output. If so, calling getDefaultTemplate( ) retrieves this NTV setting.

Tip
This method appears in code generated by Netscape Application Builder. If you are not using NAB, you typically will not need to call this method.

Return Value
A String value representing the name of the default template.

Related Topics
setDefaultTemplate( )

getErrorCodes( )
Retrieves a vector of error codes.

Syntax
public abstract Vector getErrorCodes()
Return Value
A vector of error codes that correspond to the input variables that failed validation. A code is associated with each type of data validated, as summarized in the following table:

Data to Validate
Validation Rule
Description
Number
VALIDATE_NUMBER
Data is numerical.
Integer
VALIDATE_INTEGER
Data is an integer.
Positive integer
VALIDATE_POSITIVE_INTEGER
Data is a positive integer.
Alphabetic
VALIDATE_ALPHABETIC
Data is alphabetic, a-z and/or A-Z.
US phone number
VALIDATE_US_PHONE
Data consists only of 10 digits and optionally the characters (, ), and -.
International phone number
VALIDATE_INTL_PHONE
Data consists only of numbers and the characters (, ), +, and -.
Email
VALIDATE_EMAIL
Data is in the format a@b.c
Social Security Number
VALIDATE_SSN
Data consists only of 9 digits and optionally the character -.
Date
VALIDATE_DATE
Data is in the format "MM-DD-YY" or "MM-DD-YYYY". Month, day, and year are validated accordingly.
Day
VALIDATE_DAY
Data is an integer between 1 and 31 inclusive.
Month
VALIDATE_MONTH
Data is an integer between 1 and 12 inclusive.
Year
VALIDATE_YEAR
Data is an integer between 1 and 99 inclusive, or between 1000 and 9999 inclusive.
US zipcode
VALIDATE_US_ZIPCODE
Data consists of only 5 or 9 digits and optionally the character -.

Related Topics
Chapter 13, "Taking Advantage of NAS Features," in the Programmer's Guide (Java).

getErrorMsgs( )
Retrieves a vector of error messages.

Syntax
public abstract Vector getErrorMsgs()
Return Value
A vector of error messages that correspond to the input variables that failed validation. A message is associated with each type of data validated, as summarized in the following table:

Validation Rule
Error Message
VALIDATE_NUMBER
Wrong number format!
VALIDATE_INTEGER
Wrong integer format!
VALIDATE_POSITIVE_INTEGER
Wrong positive integer format!
VALIDATE_ALPHABETIC
Wrong alphabetic format!
VALIDATE_US_PHONE
Wrong US phone format!
VALIDATE_INTL_PHONE
Wrong international phone format!
VALIDATE_EMAIL
Wrong email format!
VALIDATE_SSN
Wrong social security format!
VALIDATE_DATE
Wrong date format!
VALIDATE_DAY
Wrong day format!
VALIDATE_MONTH
Wrong month format!
VALIDATE_YEAR
Wrong year format!
VALIDATE_US_ZIPCODE
Wrong zip code format!

Related Topics
Chapter 13, "Taking Advantage of NAS Features," in the Programmer's Guide (Java).

getErrorVars( )
Retrieves a vector of input variables.

Syntax
public abstract Vector getErrorVars()
Return Value
A vector of the names of input variables that failed to validate.

Related Topics
Chapter 13, "Taking Advantage of NAS Features," in the Programmer's Guide (Java).

getHttpSessionBean( )
Retrieves an instance of a session object that is defined by the programmer.

Syntax 1
Use this syntax in most situations.

public abstract HttpSession getHttpSessionBean()
Syntax 2
Use this syntax to explicitly indicate whether to create the session or not.

public abstract HttpSession getHttpSessionBean(
	boolean create)

create. Supply a value of true if the session is to be created; otherwise, specify false.

Usage
The getHttpSessionBean( ) method retrieves the HttpSession or HttpSession2 object that is an instance of the class designated by the httpSessionBeanClass setting. This setting is defined in the SessionInfo section of an application's appInfo.ntv file. This setting allows application developers to provide bean-like HttpSession implementations.

Tip
This method appears in code generated by Netscape Application Builder. If you are not using NAB, you typically will not need to call this method.

Return Value
An HttpSession or HttpSession2 object representing an instance of the class designated by httpSessionBeanClass.

Related Topics
getSession( ) in the javax.servlet.http.HttpServletRequest interface

getServletErrorHandler( )
Retrieves the object that handles validation errors.

Syntax
public abstract IServletErrorHandler getServletErrorHandler()
Usage
This method is used to retrieve the IServletErrorHandler object that handles errors that occur during validation. You can retrieve the object elsewhere if you need to call the included functionality.

Tip
This method appears in code generated by Netscape Application Builder. If you are not using NAB, you typically will not need to call this method.

Return Value
The IServletErrorHandler object.

Related Topics
IServletErrorHandler interface

setDefaultTemplate( )
Sets the default template to another file.

Syntax
public abstract void setDefaultTemplate(
	String template)

template. The new name of the default template; the name applies only for this invocation of the servlet.

Usage
The default template is defined in a servlet's NTV file. However, in some cases it's useful to reset the default template to another file. To do so, call setDefaultTemplate( ). To retrieve the name of the current default template, call getDefaultTemplate( ).

Tip
This method appears in code generated by Netscape Application Builder. If you are not using NAB, you typically will not need to call this method.

Related Topics
getDefaultTemplate( )

setServletErrorHandler( )
Sets the IServletErrorHandler that is used to process errors.

Syntax
public abstract void setServletErrorHandler(
	IServletErrorHandler handler)

handler. The error handler to be set.

Usage
A servlet error handler is always set on a request object by default. However, you may want to implement your own, so the setServletErrorHandler( ) method is provided to allow that.

This method sets the IServletErrorHandler that is used to process errors that happen during validation (and possibly elsewhere). To retrieve the IServletErrorHandler, call getServletErrorHandler( ).

Tip
This method appears in code generated by Netscape Application Builder. If you are not using NAB, you typically will not need to call this method.

Related Topics
getServletErrorHandler( )

validate( )
Validates input parameters and session variables.

Syntax 1
Use this version to validate all input parameters and session variables listed in the servlet's NTV file. This version also streams out an error on failure.

public abstract boolean validate(
	HttpServletResponse response) 
	throws ServletException, IOException
Syntax 2
Use this version to validate specific input parameters and session variables (or those listed in the servlet's NTV file). This version also streams out an error on failure.

public abstract boolean validate(
	String params[],
	String sessionVars[],
	HttpServletResponse response) 
	throws ServletException, IOException
Syntax 3
Use this version to validate specific input parameters and session variables (or those listed in the servlet's NTV file). No error streaming occurs.

public abstract boolean validate(
	String params[],
	String sessionVars[])
Syntax 4
Use this version to validate all input parameters and session variables listed in the servlet's NTV file. No error streaming occurs.

public abstract boolean validate()

response. The HttpServletResponse object.

params. The array of parameters to validate. Specify NULL to validate all input parameters listed in the NTV file.

sessionVars. The array of session variables to validate. Specify NULL to validate all session variables listed in the NTV file.

Usage
Use this method whenever you want to validate parameters. There are four ways to invoke the validate( ) method. One version validates all input and session variables listed in a servlet's NTV file. Another version validates a specified array of input parameters or session variables. For each of these two versions, you can either ignore failure conditions or stream an error on failure.

When validate( ) is called and a validation error is detected, validate( ) then calls either of two IServletErrorHandler methods: handleInputValueError( ) or handleSessionVariableError( ). The previous two methods might return a positive number, meaning that a real error occurred and is queued into the error-specific vectors. If this happens, then streamError( ) is called once before validate( ) returns (assuming the validate( ) call is one of the two variants that streams errors).

The validate( ) method passes in one of the following error types as input to the two error handler methods, handleInputValueError( ) or handleSessionVariableError( ):

Error Type
Value
Error because data must be ...
ERROR_NUMBER
5
a number.
ERROR_INTEGER
6
an integer.
ERROR_POSITIVE_INTEGER
7
a positive integer.
ERROR_ALPHABETIC
8
alphabetic characters (a-z, A-Z, or both).
ERROR_US_PHONE
9
a phone number containing at most 10 digits and optional characters (, ), and -.
ERROR_INTL_PHONE
10
a phone number containing only digits and optional characters, (, ), +, and -.
ERROR_EMAIL
11
an address of the form a@b.c.
ERROR_SSN
12
a Social Security Number containing 9 digits and an optional - character.
ERROR_DATE
13
a date of the form MM-DD-YY or MM-DD-YYYY.
ERROR_DAY
14
an integer between 1 and 31 inclusive.
ERROR_MONTH
15
an integer between 1 and 12 inclusive.
ERROR_YEAR
16
an integer between 1 and 99 inclusive or between 1000 and 9999 inclusive.
ERROR_ZIP
17
a ZIP code containing either 5 digits or 9 digits, and an optional - character.

Return Value
Returns true if the validation was successful; otherwise, returns false.

Related Topics
IServletErrorHandler interface

 

© Copyright 1999 Netscape Communications Corp.