Skip Headers

Oracle® interMedia Java Classes User's Guide and Reference
Release 9.2
Part No. A96121-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Previous Next

9
Java Classes for Servlets and JSP Reference Information

Oracle interMedia Java Classes for servlets and JavaServer Pages (JSP) facilitates retrieving and uploading media data from and to an Oracle database.

The OrdHttpResponseHandler class facilitates the retrieval of media data from an Oracle database, and its delivery to a browser or other HTTP client from a Java servlet. The OrdHttpJspResponseHandler class provides the same features for JSP.

Form-based file uploading using HTML forms encodes form data and uploaded files in POST requests using the multipart/form-data format. The OrdHttpUploadFormData class facilitates the processing of such requests by parsing the POST data and making the contents of regular form fields and the contents of uploaded files readily accessible to Java servlets or JSP. The handling of uploaded files is facilitated by the OrdHttpUploadFile class, which provides an easy-to-use API that applications call to load image, audio, and video data into a database.

9.1 Prerequisites

You will need to include the following import statements in your Java file in order to execute interMedia methods:

import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import oracle.jdbc.driver.*;
import oracle.sql.*;
import oracle.ord.im.*;

OrdHttpResponseHandler Reference Information

This section presents reference information on the methods of the OrdHttpResponseHandler class.

The OrdHttpResponseHandler class facilitates the retrieval of media data from an Oracle database, and its delivery to a browser or other HTTP client from a Java servlet.

An interMedia Java object, such as an OrdImage object, is not dependent on the JDBC statement or result set from which it was obtained. However, an interMedia Java object is dependent on the JDBC connection it is using and on which the SQL statement was executed, or from which the result set was obtained. Therefore, having obtained an interMedia Java object from the database, an application must not release the JDBC connection before delivering the media data to the browser.

This class contains the following field:

The following example shows how to use the OrdHttpResponseHandler class to retrieve an image from a database and deliver it to a browser:

PreparedStatement stmt = conn.prepareStatement("select photo from photo_album 
     where id = ?");
stmt.setString(1, request.getParameter("photo_id"));
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (rset.next( )){
     OrdImage media = (OrdImage)rset.getCustomDatum(1, OrdImage.getFactory( ));
     OrdHttpResponseHandler handler = new OrdHttpResponseHandler(request,
          response);
     handler.sendImage(media);
}
else{
     response.setStatus(response.SC_NOT_FOUND);
}
rset.close( );
stmt.close( );
A Note on the Use of Charsets Other Than ISO-8859-1 (Latin-1)

If you wish to retrieve from an OrdDoc object a text-based document with a character set (charset) other than ISO-8859-1 (also called Latin-1), and deliver that document to a browser, your application must specify the charset name in the HTTP Content-Type header.

If the charset specification is included in the MIME type attribute in the OrdDoc object, then your application needs to call only the sendDoc( ) method to retrieve the document and deliver it to the browser. For example, an HTML page that is written in Japanese might be stored in the OrdDoc object with a MIME type of text/html; charset=Shift_JIS. In this case, calling the sendDoc( ) method will send the appropriate Content-Type header, allowing the browser to display the page correctly.

However, if the MIME type in the OrdDoc object does not include the charset specification, then you must call one of the sendResponse( ) methods and specify the MIME type explicitly. For example, if the MIME type of an HTML page written in Japanese is stored in the OrdDoc object as text/html, and the charset name is specified in a separate column, then the application must append the charset specification to the MIME type before calling a sendResponse( ) method. For example:

OraclePreparedStatement stmt = (OraclePreparedStatement)conn.prepareStatement(
     "select doc, charset from documents where id = ?");
stmt.setString(1, request.getParameter("id");
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (rset.next( )){
     OrdDoc doc = (OrdDoc)rset.getCustomDatum(1, OrdDoc.getFactory( ));
     String charset = rset.getString(2);
     String mimeType = doc.getMimeType( ) + "; charset=" + charset;
     OrdHttpResponseHandler handler = new OrdHttpResponseHandler(request,
          response);
     handler.sendResponse(mimeType, doc.getContentLength( ), doc.getContent( ), 
          doc.getUpdateTime( ));
}
else{
     response.setStatus(response.SC_NOT_FOUND);
}
rset.close( );
stmt.close( );


OrdHttpResponseHandler( )

Format

public OrdHttpResponseHandler( )

Description

Creates an OrdHttpResponseHandler object to handle the response to a multimedia retrieval request. The application must subsequently specify the HttpServletResponse object by calling the setServletResponse( ) method, and can optionally specify the HttpServletRequest object by calling the setServletRequest( ) method.

Parameters

None.

Return Value

None.

Exceptions

None.

Examples

See setServletRequest( ) for an example of this method.


OrdHttpResponseHandler(HttpServletRequest,HttpServletResponse)

Format

public OrdHttpResponseHandler(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)

Description

Creates an OrdHttpResponseHandler object to handle the response to a multimedia retrieval request and specifies the HttpServletRequest and HttpServletResponse objects for the response handler.

Parameters

request

An object of type HttpServletRequest.

response

An object of type HttpServletResponse.

Return Value

None.

Exceptions

None.

Examples

See sendAudio( ) for an example of this method.


sendAudio( )

Format

public void sendAudio(oracle.ord.im.OrdAudio media)

Description

Retrieves an audio clip from an OrdAudio object and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.

Parameters

media

An object of type oracle.ord.im.OrdAudio.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest or HttpServletResponse has not been specified.

OrdHttpResponseException

This exception is thrown if the source type is not recognized.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

OraclePreparedStatement stmt = (OraclePreparedStatement)
     conn.prepareStatement("select media from sounds where id = ?");
stmt.setString(1, request.getParameter("id"));
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (rset.next( )){
     OrdAudio media = (OrdAudio)rset.getCustomDatum(1, OrdAudio.getFactory( ));
     OrdHttpResponseHandler handler = new OrdHttpResponseHandler
          (request, response);
     handler.sendAudio(media);
     return;
}
else{
     response.setStatus(response.SC_NOT_FOUND);
}

where:


sendDoc( )

Format

public void sendDoc(oracle.ord.im.OrdDoc media)

Description

Retrieves media data from an OrdDoc object and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.

Parameters

media

An object of type oracle.ord.im.OrdDoc.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest or HttpServletResponse has not been specified.

OrdHttpResponseException

This exception is thrown if the source type is not recognized.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

OraclePreparedStatement stmt = (OraclePreparedStatement)
     conn.prepareStatement("select media from documents where id = ?");
stmt.setString(1, request.getParameter("id"));
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (rset.next( )){
     OrdDoc media = (OrdDoc)rset.getCustomDatum(1, OrdDoc.getFactory( ));
     OrdHttpResponseHandler handler = new OrdHttpResponseHandler
          (request, response);
     handler.sendDoc(media);
     return;
}
else{
     response.setStatus(response.SC_NOT_FOUND);
}

where:


sendImage( )

Format

public void sendImage(oracle.ord.im.OrdImage media)

Description

Retrieves an image from an OrdImage object and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.

Parameters

media

An object of type oracle.ord.im.OrdImage.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest or HttpServletResponse has not been specified.

OrdHttpResponseException

This exception is thrown if the source type is not recognized.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

OraclePreparedStatement stmt = (OraclePreparedStatement)
     conn.prepareStatement("select media from photos where id = ?");
stmt.setString(1, request.getParameter("id"));
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (rset.next( )){
     OrdImage media = (OrdImage)rset.getCustomDatum(1, OrdImage.getFactory( ));
     OrdHttpResponseHandler handler = new OrdHttpResponseHandler
          (request, response);
     handler.sendImage(media);
     return;
}
else{
     response.setStatus(response.SC_NOT_FOUND);
}

where:


sendResponse(String,int,BFILE,Timestamp)

Format

public void sendResponse(String contentType, int length, oracle.sql.BFILE bfile,
java.sql.Timestamp lastModified)

Description

Builds the HTTP response header, then retrieves the contents of the BFILE from the database and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.

Parameters

contentType

A string that specifies the MIME type of the content.

length

An integer that specifies the length of the data.

bfile

An oracle.sql.BFILE from which the media data is retrieved.

lastModified

A java.sql.Timestamp object that specifies the date and time when the data was last modified, or null if no last modified date and time are available.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest or HttpServletResponse has not been specified.

java.lang.IllegalArgumentException

This exception is thrown if the length is negative.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

OraclePreparedStatement stmt = (OraclePreparedStatement)conn.prepareStatement
     ("select mimetype, len, doc, updatetime from docfiles where id = ?");
stmt.setString( 1, request.getParameter("id"));
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (rset.next( )){
     String mimeType = rset.getString(1);
     int len = rset.getInt(2);
     BFILE bfile = rset.getBFILE(3);
     Timestamp updateTime = rset.getTimestamp(4);
     OrdHttpResponseHandler handler = new OrdHttpResponseHandler
          (request, response);
     handler.sendResponse(mimeType, len, bfile, updateTime);
     return;
}
else{
     response.setStatus(response.SC_NOT_FOUND);
}




sendResponse(String,int,BLOB,Timestamp)

Format

public void sendResponse(String contentType, int length, oracle.sql.BLOB blob,
java.sql.Timestamp lastModified)

Description

Builds the HTTP response header, then retrieves the contents of the BLOB from the database and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.

Parameters

contentType

A string that specifies the MIME type of the content.

length

An integer that specifies the length of the data.

blob

An oracle.sql.BLOB from which the media data is retrieved.

lastModified

A java.sql.Timestamp object that specifies the date and time when the data was last modified, or null if no last modified date and time are available.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest or HttpServletResponse has not been specified.

java.lang.IllegalArgumentException

This exception is thrown if the length is negative.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

OraclePreparedStatement stmt = (OraclePreparedStatement)conn.prepareStatement
     ("select mimetype, len, doc, updatetime from docblobs where id = ?");
stmt.setString(1, request.getParameter("id"));
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (rset.next( )){
     String mimeType = rset.getString(1);
     int len = rset.getInt(2);
     BLOB blob = rset.getBLOB(3);
     Timestamp updateTime = rset.getTimestamp(4);
     OrdHttpResponseHandler handler = new OrdHttpResponseHandler
          (request, response);
     handler.sendResponse(mimeType, len, blob, updateTime);
     return;
}
else{
     response.setStatus(response.SC_NOT_FOUND);
}




sendResponse(String,int,InputStream,Timestamp)

Format

public void sendResponse(String contentType, int length, java.io.InputStream in,
java.sql.Timestamp lastModified)

Description

Builds the HTTP response header, then retrieves the contents of the InputStream object and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.

Parameters

contentType

A String that specifies the MIME type of the content.

length

An integer that specifies the length of the data.

in

An InputStream object from which the media data is retrieved.

lastModified

A java.sql.Timestamp object that specifies the date and time when the data was last modified, or null if no last modified date and time are available.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest or HttpServletResponse has not been specified.

java.lang.IllegalArgumentException

This exception is thrown if the length is negative.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

OraclePreparedStatement stmt = (OraclePreparedStatement)conn.prepareStatement
     ("select mimetype, len, doc, updatetime from docblobs where id = ?");
stmt.setString(1, request.getParameter("id"));
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if ( rset.next( ) ){
     String mimeType = rset.getString(1);
     int len = rset.getInt(2);
     BLOB blob = rset.getBLOB(3);
     Timestamp updateTime = rset.getTimestamp(4);
     InputStream blobInputStream = blob.getBinaryStream( );
     OrdHttpResponseHandler handler = new OrdHttpResponseHandler
          (request, response);
     handler.sendResponse(mimeType, len, blobInputStream, updateTime);
     return;
}
else{
     response.setStatus(response.SC_NOT_FOUND);
}




sendResponseBody(int,BFILE)

Format

public void sendResponseBody(int length, oracle.sql.BFILE bfile)

Description

Retrieves the contents of a BFILE from the database and delivers it as the response body to the browser. The caller is responsible for building the HTTP header.

Parameters

length

An integer that specifies the length of the data.

bfile

An oracle.sql.BFILE from which the content is retrieved.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest has not been specified.

java.lang.IllegalArgumentException

This exception is thrown if the length is negative.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

OraclePreparedStatement stmt = (OraclePreparedStatement)conn.prepareStatement
     ("select mimetype, len, doc from docfiles where id = ?");
stmt.setString(1, request.getParameter("id"));
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (rset.next( )){
     String mimeType = rset.getString(1);
     int len = rset.getInt(2);
     BFILE bfile = rset.getBFILE(3);
     response.setContentLength(len);
     response.setContentType(mimeType);
     OrdHttpResponseHandler handler = new OrdHttpResponseHandler( );
     handler.setServletResponse(response);
     handler.sendResponseBody(len, bfile);
     return;
}
else{
     response.setStatus(response.SC_NOT_FOUND);
}




sendResponseBody(int,BLOB)

Format

public void sendResponseBody(int length, oracle.sql.BLOB blob)

Description

Retrieves the contents of a BLOB from the database and delivers it as the response body to the browser. The caller is responsible for building the HTTP header.

Parameters

length

An integer that specifies the length of the data.

blob

An oracle.sql.BLOB from which the content is retrieved.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest has not been specified.

java.lang.IllegalArgumentException

This exception is thrown if the length is negative.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

OraclePreparedStatement stmt = (OraclePreparedStatement)conn.prepareStatement
     ("select mimetype, len, doc from docblobs where id = ?");
stmt.setString( 1, request.getParameter("id"));
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (rset.next( )){
     String mimeType = rset.getString(1);
     int len = rset.getInt(2);
     BLOB blob = rset.getBLOB(3);
     response.setContentLength(len);
     response.setContentType(mimeType);
     OrdHttpResponseHandler handler = new OrdHttpResponseHandler( );
     handler.setServletResponse(response);
     handler.sendResponseBody(len, blob);
     return;
}
else{
     response.setStatus(response.SC_NOT_FOUND);
}




sendResponseBody(int,InputStream)

Format

public void sendResponseBody(int length, java.io.InputStream in)

Description

Retrieves the contents of the InputStream object and delivers it to the client. The caller is responsible for building the HTTP header.

Parameters

length

An integer that specifies the length of the data.

in

An InputStream object from which the media data is retrieved.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest has not been specified.

java.lang.IllegalArgumentException

This exception is thrown if the length is negative.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

OraclePreparedStatement stmt = (OraclePreparedStatement)conn.prepareStatement
     ("select mimetype, len, doc from docblobs where id = ?");
stmt.setString(1, request.getParameter("id"));
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (rset.next( )){
     String mimeType = rset.getString(1);
     int len = rset.getInt(2);
     BLOB blob = rset.getBLOB(3);
     response.setContentLength(len);
     response.setContentType(mimeType);
     InputStream blobInputStream = blob.getBinaryStream( );
     OrdHttpResponseHandler handler = new OrdHttpResponseHandler( );
     handler.setServletResponse(response);
     handler.sendResponseBody(len, blobInputStream);
     return;
}
else{
     response.setStatus(response.SC_NOT_FOUND);
}




sendVideo( )

Format

public void sendVideo(oracle.ord.im.OrdVideo media)

Description

Retrieves a video clip from an OrdVideo object and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers.

Parameters

media

An object of type oracle.ord.im.OrdVideo.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest or HttpServletResponse has not been specified.

OrdHttpResponseException

This exception is thrown if the source type is not recognized.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

OraclePreparedStatement stmt = (OraclePreparedStatement)
     conn.prepareStatement("select video from movies where id = ?");
stmt.setString(1, request.getParameter("id"));
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (rset.next( )){
     OrdVideo media = (OrdVideo)rset.getCustomDatum(1, OrdVideo.getFactory( ));
     OrdHttpResponseHandler handler = new OrdHttpResponseHandler
          (request, response);
     handler.sendVideo(media);
     return;
}
else{
     response.setStatus( response.SC_NOT_FOUND );
}

where:


setBufferSize( )

Format

public void setBufferSize(int bufferSize)

Description

Sets the buffer size for LOB read and response write operations.

Parameters

bufferSize

An integer that specifies the buffer size.

Return Value

None.

Exceptions

java.lang.IllegalArgumentException

This exception is thrown if the buffer size is negative or zero.

Examples

OrdHttpResponseHandler handler = new OrdHttpResponseHandler(request, response);
handler.setBufferSize(16000);




setServletRequest( )

Format

public void setServletRequest(javax.servlet.http.HttpServletRequest request)

Description

Specifies the HttpServletRequest object for this response handler. You must call this method if you did not specify the HttpServletRequest object in the constructor and you want to call any of the send methods other than the sendResponseBody methods. You do not need to call this method if you call only the sendResponseBody methods.

Parameters

request

An object of type HttpServletRequest.

Return Value

None.

Exceptions

None.

Examples

OrdHttpResponseHandler handler = new OrdHttpResponseHandler( );
handler.setServletRequest(request);
handler.setServletResponse(response);




setServletResponse( )

Format

public void setServletResponse(javax.servlet.http.HttpServletResponse response)

Description

Specifies the HttpServletResponse object for this response handler. You must call this method before calling any of the send methods if you did not specify the HttpServletResponse object in the constructor.

Parameters

response

An object of type HttpServletResponse.

Return Value

None.

Exceptions

None.

Examples

See setServletRequest( ) for an example of this method.


OrdHttpJspResponseHandler Reference Information

This section presents reference information on the methods of the OrdHttpJspResponseHandler class.

The OrdHttpJspResponseHandler class facilitates the retrieval of media data from an Oracle database, and its delivery to a browser or another HTTP client from a JSP.

This class inherits the DEFAULT_BUFFER_SIZE field from the OrdHttpResponseHandler class.

An Important Note on JSP Engines

JSP engines are not required to support access to the servlet binary output stream. Therefore, not all JSP engines support the delivery of media data using the OrdHttpJspResponseHandler class.All media data stored in the database using the interMedia types, including text documents stored using the OrdDoc type, is stored using a binary LOB data type. Media data stored internally in the database is stored using a BLOB. Media data stored in an operating system file outside the database is stored using a BFILE. Therefore, all media data is delivered to the browser through the servlet binary output stream, using the ServletOutputStream class.All the send methods in the OrdHttpJspResponseHandler class mirror the initial processing of the jsp:forward tag. Specifically, these send methods call the JspWriter.clear method to clear the output buffer of the page prior to obtaining the binary output stream. However, JSP engines are not required to support a call to the ServletResponse.getOutputStream method from within a JSP. A JSP engine that does not support this typically throws an IllegalStateException error from the getOutputStream method. However, the exact behavior is implementation-specific. If your JSP engine does not support access to the binary output stream from within a JSP, then you must use a servlet to deliver media data. For example, perform one of the following operations:

An Important Note on Return Statements

When delivering media data from a JSP, a return statement is always required following a call to any of the send methods of the OrdHttpJspResponseHandler class. The return statement is necessary to ensure that no other data is written to the output stream of the JSP following the media data.An if ( true ) { ... return; } construct may be used to avoid the "statement not reachable" error that may result from the presence of additional code, generated by the JSP engine, at the end of a compiled page. This construct, which mirrors exactly the code produced by some JSP engines to handle the <jsp:forward ... > directive, is shown in the example provided later in this section.


Note:

An interMedia Java object, such as an OrdImage object, is not dependent on the JDBC statement or result set from which it was obtained. However, an interMedia Java object is dependent on the JDBC connection it is using and on which the SQL statement was executed or from which the result set was obtained. Therefore, having obtained an interMedia Java object from the database, an application must not release the JDBC connection before delivering the media data to the browser.

All the send methods in this class call the JspWriter.clear method to clear the page's output buffer prior to delivering the image. Therefore, the page must use the buffered output model, which is the default.

The following example demonstrates how to use the OrdHttpJspResponseHandler class to retrieve an image from a database and deliver it to a browser. The return statement ensures that the trailing newline characters following the final end tag (represented by a percent mark and right-angle bracket, or %> ) are not transmitted to the browser as part of the image.

The if ( true ) { ... return; } construct is used to avoid the "statement not reachable" error that would otherwise be produced by this example due to the additional statements, generated by the JSP engine, at the end of the compiled page.

<%@ page language="java" %>
<%@ page import="OrdSamplePhotoAlbumBean" %>
<%@ page import="oracle.ord.im.OrdHttpJspResponseHandler" %>


<jsp:useBean id="photos" scope="page" 
             class="OrdSamplePhotoAlbumBean"/>
<jsp:useBean id="handler" scope="page"
             class="oracle.ord.im.OrdHttpJspResponseHandler"/>


<%
     // Select the entry from the table using the ID request parameter,
     // then fetch the row.
     
     photos.selectRowById(request.getParameter("id"));
     if (!photos.fetch( )){
          response.setStatus(response.SC_NOT_FOUND);
          return;
     }


     // Set the page context for the retrieve request, then retrieve
     // the image from the database and deliver it to the browser. The
     // getImage( ) method returns an object of type oracle.ord.im.OrdImage.


     if (true){
          handler.setPageContext(pageContext);
          handler.sendImage(photos.getImage( ));
          return;
     }
%>


OrdHttpJspResponseHandler( )

Format

public OrdHttpJspResponseHandler( )

Description

Creates an OrdHttpJspResponseHandler object to handle the response to a multimedia retrieval request. The application must subsequently specify the PageContext object by calling the setPageContext( ) method.

Parameters

None.

Return Value

None.

Exceptions

None.

Examples

The default constructor is typically invoked implicitly when the OrdHttpJspResponseHandler class is used as a JavaBean. See setPageContext( ) for an example of the implicit use of the constructor.


OrdHttpJspResponseHandler(PageContext)

Format

public OrdHttpJspResponseHandler(javax.servlet.jsp.PageContext pageContext)

Description

Creates an OrdHttpJspResponseHandler object to handle the response to a multimedia retrieval request, and specifies the PageContext object for the response handler.

Parameters

pageContext

An object of type PageContext.

Return Value

None.

Exceptions

None.

Examples

OrdHttpJspResponseHandler handler = new OrdHttpJspResponseHandler(pageContext);




sendAudio( )

Format

public void sendAudio(oracle.ord.im.OrdAudio media)

Description

Retrieves an audio clip from an OrdAudio object and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers. This method calls the JspWriter.clear method to clear the output buffer of the page prior to delivering the audio clip. Therefore, the page must use the buffered output model, which is the default.

Parameters

media

An object of type oracle.ord.im.OrdAudio.

Return Value

This method overrides the sendAudio( ) method in class OrdHttpResponseHandler.

Exceptions

java.lang.IllegalStateException

This exception is thrown if PageContext has not been specified.

OrdHttpResponseException

This exception is thrown if the source type is not recognized.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

The OrdHttpJspResponseHandler.sendAudio( ) method extends the OrdHttpResponseHandler.sendAudio( ) method. See sendAudio( ) in OrdHttpResponseHandler Reference Information for an example of this method in the base class.


sendDoc( )

Format

public void sendDoc(oracle.ord.im.OrdDoc media)

Description

Retrieves media data from an OrdDoc object and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers. This method calls the JspWriter.clear method to clear the output buffer of the page prior to delivering the media. Therefore, the page must use the buffered output model, which is the default.

Parameters

media

An object of type oracle.ord.im.OrdDoc.

Return Value

This method overrides the sendDoc( ) method in class OrdHttpResponseHandler.

Exceptions

java.lang.IllegalStateException

This exception is thrown if PageContext has not been specified.

OrdHttpResponseException

This exception is thrown if the source type is not recognized.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

The OrdHttpJspResponseHandler.sendDoc( ) method extends the OrdHttpResponseHandler.sendDoc( ) method. See sendDoc( ) in OrdHttpResponseHandler Reference Information for an example of this method in the base class.


sendImage( )

Format

public void sendImage(oracle.ord.im.OrdImage media)

Description

Retrieves an image from an OrdImage object and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers. This method calls the JspWriter.clear method to clear the output buffer of the page prior to delivering the image. Therefore, the page must use the buffered output model, which is the default.

Parameters

media

An object of type oracle.ord.im.OrdImage.

Return Value

This method overrides the sendImage( ) method in class OrdHttpResponseHandler.

Exceptions

java.lang.IllegalStateException

This exception is thrown if PageContext has not been specified.

OrdHttpResponseException

This exception is thrown if the source type is not recognized.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

The OrdHttpJspResponseHandler.sendImage( ) method extends the OrdHttpResponseHandler.sendImage( ) method. See sendImage( ) in OrdHttpResponseHandler Reference Information for an example of this method in the base class.


sendResponse(String,int,BFILE,Timestamp)

Format

public void sendResponse(String contentType, int length, oracle.sql.BFILE bfile,
java.sql.Timestamp lastModified)

Description

Builds the HTTP response header, then retrieves the contents of the BFILE from the database and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers. This method calls the JspWriter.clear method to clear the output buffer of the page prior to delivering the image. Therefore, the page must use the buffered output model, which is the default.

Parameters

contentType

A String that specifies the MIME type of the content.

length

An integer that specifies the length of the data.

bfile

An object of type oracle.sql.BFILE.

lastModified

A java.sql.Timestamp object that specifies the date and time when the data was last modified, or null if no last modified date and time are available.

Return Value

This method overrides the sendResponse( ) method in class OrdHttpResponseHandler.

Exceptions

java.lang.IllegalStateException

This exception is thrown if PageContext has not been specified.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

java.lang.IllegalArgumentException

This exception is thrown if the length is negative.

Examples

The OrdHttpJspResponseHandler.sendResponse(String, int, BFILE, Timestamp) method extends the OrdHttpResponseHandler.sendResponse(String, int, BFILE, Timestamp) method. See sendResponse(String,int,BFILE,Timestamp) in OrdHttpResponseHandler Reference Information for an example of this method in the base class.


sendResponse(String,int,BLOB,Timestamp)

Format

public void sendResponse(String contentType, int length, oracle.sql.BLOB blob,
java.sql.Timestamp lastModified)

Description

Builds the HTTP response header, then retrieves the contents of the BLOB from the database and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers. This method calls the JspWriter.clear method to clear the output buffer of the page prior to delivering the image. Therefore, the page must use the buffered output model, which is the default.

Parameters

contentType

A String that specifies the MIME type of the content.

length

An integer that specifies the length of the data.

blob

An object of type oracle.sql.BLOB.

lastModified

A java.sql.Timestamp object that specifies the date and time when the data was last modified, or null if no last modified date and time are available.

Return Value

This method overrides the sendResponse( ) method in class OrdHttpResponseHandler.

Exceptions

java.lang.IllegalStateException

This exception is thrown if PageContext has not been specified.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

java.lang.IllegalArgumentException

This exception is thrown if the length is negative.

Examples

The OrdHttpJspResponseHandler.sendResponse(String, int, BLOB, Timestamp) method extends the OrdHttpResponseHandler.sendResponse(String, int, BLOB, Timestamp) method. See sendResponse(String,int,BLOB,Timestamp) in OrdHttpResponseHandler Reference Information for an example of this method in the base class.


sendResponse(String,int,InputStream,Timestamp)

Format

public void sendResponse(String contentType, int length, java.io.InputStream in,
java.sql.Timestamp lastModified)

Description

Builds the HTTP response header, then retrieves the contents of the InputStream object and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers. This method calls the JspWriter.clear method to clear the output buffer of the page prior to delivering the image. Therefore, the page must use the buffered output model, which is the default.

Parameters

contentType

A String that specifies the MIME type of the content.

length

An integer that specifies the length of the data.

in

An InputStream object from which the media data is retrieved.

lastModified

A java.sql.Timestamp object that specifies the date and time when the data was last modified, or null if no last modified date and time are available.

Return Value

This method overrides the sendResponse( ) method in class OrdHttpResponseHandler.

Exceptions

java.lang.IllegalStateException

This exception is thrown if PageContext has not been specified.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

java.lang.IllegalArgumentException

This exception is thrown if the length is negative.

Examples

The OrdHttpJspResponseHandler.sendResponse(String, int, InputStream, Timestamp) method extends the OrdHttpResponseHandler.sendResponse(String, int, InputStream, Timestamp) method. See sendResponse(String,int,InputStream,Timestamp) in OrdHttpResponseHandler Reference Information for an example of this method in the base class.


sendVideo( )

Format

public void sendVideo(oracle.ord.im.OrdVideo media)

Description

Retrieves a video clip from an OrdVideo object and delivers it to the browser.

This method supports browser content caching by supporting the If-Modified-Since and Last-Modified headers. This method calls the JspWriter.clear method to clear the output buffer of the page prior to delivering the video clip. Therefore, the page must use the buffered output model, which is the default.

Parameters

media

An object of type oracle.ord.im.OrdVideo.

Return Value

This method overrides the sendVideo( ) method in class OrdHttpResponseHandler.

Exceptions

java.lang.IllegalStateException

This exception is thrown if PageContext has not been specified.

OrdHttpResponseException

This exception is thrown if the source type is not recognized.

javax.servlet.ServletException

This exception is thrown if an error occurs accessing the binary output stream.

java.sql.SQLException

This exception is thrown if an error occurs obtaining an InputStream object to read the media data.

java.io.IOException

This exception is thrown if an error occurs reading the media data.

Examples

The OrdHttpJspResponseHandler.sendVideo( ) method extends the OrdHttpResponseHandler.sendVideo( ) method. See sendVideo( ) in OrdHttpResponseHandler Reference Information for an example of this method in the base class.


setPageContext( )

Format

public void setPageContext(javax.servlet.jsp.PageContext pageContext)

Description

Specifies the PageContext object for this response handler. You must call this method before calling any of the send methods if you did not specify the PageContext object in the constructor.

Parameters

pageContext

An object of type PageContext.

Return Value

None.

Exceptions

None.

Examples

<jsp:useBean id="handler" scope="page"
             class="oracle.ord.im.OrdHttpJspResponseHandler"/>
<%
     OraclePreparedStatement stmt = (OraclePreparedStatement)
          conn.prepareStatement("select image from photos where id = ?");
     stmt.setString(1, request.getParameter("id"));
     OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
     if (rset.next( )){
          OrdImage media = (OrdImage)rset.getCustomDatum(1,
               OrdImage.getFactory( ));
          handler.setPageContext(pageContext);
          handler.sendImage(image);
          return;
     }else{
          response.setStatus(response.SC_NOT_FOUND);
     }
%>


OrdHttpUploadFile Reference Information

This section presents reference information on the methods of the OrdHttpUploadFile class.

Form-based file uploading using HTML forms encodes form data and uploaded files in POST requests using the multipart/form-data format. The OrdHttpUploadFile class is used to represent an uploaded file that has been parsed by the OrdHttpUploadFormData class (see OrdHttpUploadFormData Reference Information for more information on the OrdHttpUploadFormData class). The OrdHttpUploadFile class provides methods to obtain information about the uploaded file, to access the contents of the file directly, and to facilitate loading the contents into an interMedia object in a database.

Every input field of type FILE in an HTML form will produce a parameter of type OrdHttpUploadFile, whether or not a user enters a valid file name into such a field. Depending on the requirements, applications can test the length of the file name, the length of the content, or both to determine if a valid file name was entered by a user and if the file was successfully uploaded by the browser. For example, if a user does not enter a file name, the length of the String returned by the getOriginalFileName( ) method will be zero. However, if a user enters an invalid file name or the name of an empty (zero-length) file, then the content length returned by the getContentLength( ) method will be zero, even though the length of the file name will not be zero.


getContentLength( )

Format

public int getContentLength( )

Description

Returns the length of the uploaded media file. If you enter an invalid file name, the name of a nonexistent file, or the name of an empty file, the length returned is zero.

Parameters

None.

Return Value

This method returns the length of the uploaded file.

Exceptions

None.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request);
formData.parseFormData( );
...
OrdHttpUploadFile photo = formData.getFileParameter("photo");
String mimeType = photo.getMimeType( );
int i = photo.getContentLength( );
if (i == 0){
     displayUserError("The file is empty, invalid, or nonexistent");
}
...
photo.release( );



getInputStream( )

Format

public java.io.InputStream getInputStream( )

Description

Returns an InputStream object that can be used to read uploaded data directly. Applications should close the stream with the close( ) method when finished.

Parameters

None.

Return Value

This method returns an InputStream object, from which to read the contents.

Exceptions

java.lang.IllegalStateException

This exception is thrown if the uploaded file is no longer available because it has been released.

java.io.IOException

This exception is thrown if an error occurs opening the temporary file.

Examples

OrdImage dbImage = (OrdImage)rset.getCustomDatum(1, OrdImage.getFactory( ));
OrdHttpUploadFile uploadImage = formData.getFileParameter("photo");
InputStream photoInputStream = uploadImage.getInputStream( );
try{
     dbImage.loadDataFromInputStream(photoInputStream);
}
finally{
     photoInputStream.close( );
}




getMimeType( )

Format

public String getMimeType( )

Description

Returns the MIME type of the media file, as determined by the browser when the file is uploaded.

Some browsers return a default MIME type even if you do not supply a file name; therefore, the application should check the file name or content length to ensure the file was uploaded successfully.

Parameters

None.

Return Value

This method returns the MIME type of the file, as a String.

Exceptions

None.

Examples

See getContentLength( ) for an example of this method.


getOriginalFileName( )

Format

public String getOriginalFileName( )

Description

Returns the original file name, as provided by the browser. If you do not supply a file name, an empty String is returned.

Parameters

None.

Return Value

This method returns the file name, as a String.

Exceptions

None.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request);
formData.parseFormData( );
...
OrdHttpUploadFile photo = formData.getFileParameter("photo");
String originalName = photo.getOriginalFileName( );
...
formData.release( );




getSimpleFileName( )

Format

public String getSimpleFileName( )

Description

Returns the simple file name (that is, the name of the file and the extension). If you do not supply a file name, an empty String is returned.

Parameters

None.

Return Value

This method returns the simple file name, as a String.

Exceptions

None.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request);
formData.parseFormData( );
...
OrdHttpUploadFile photo = formData.getFileParameter("photo");
String name = photo.getSimpleFileName( );
...
formData.release( );




loadAudio(OrdAudio)

Format

public void loadAudio(oracle.ord.im.OrdAudio media)

Description

Loads the uploaded file into an OrdAudio Java object and sets the properties based on the audio data. This method loads the audio data into the database and calls the OrdAudio.setProperties( ) method to set the properties, such as the MIME type. This method does not use any existing format plug-in context information and does not set any comments when setting the properties. To use this method, the application fetches an initialized OrdAudio object from the database, calls this method to load the audio data into the database, and then updates the OrdAudio object in the database.

If the call to the setProperties( ) method fails because the audio format is not recognized, this method sets the following properties:

Parameters

media

An oracle.ord.im.OrdAudio object into which the audio data will be loaded.

Return Value

None.

Exceptions

java.io.IOException

This exception is thrown if an error occurs while reading or writing the media data.

java.sql.SQLException

This exception is thrown if an unrecognized error occurs while storing the media data.

java.lang.IllegalStateException

This exception is thrown if the uploaded file is no longer available because it has been released.

Example

OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request);
formData.parseFormData( );
String id = formData.getParameter("id");
OrdHttpUploadFile uploadFile = formData.getFileParameter("soundfile");


OraclePreparedStatement stmt = (OraclePreparedStatement)
     conn.prepareStatement("insert into songs (id,sound) values(?,
     ORDSYS.ORDAUDIO.INIT( ))");
stmt.setString(1, id);
stmt.executeUpdate( );
stmt.close( );


stmt = (OraclePreparedStatement)conn.prepareStatement("select sound from
     songs where id = ? for update");
stmt.setString(1, id);
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (!rset.next( )){
     throw new ServletException("new row not found in table");
}


OrdAudio sound = (OrdAudio)rset.getCustomDatum(1, OrdAudio.getFactory( ));
uploadFile.loadAudio(sound);
formData.release( );


rset.close( );
stmt.close( );


stmt = (OraclePreparedStatement)conn.prepareStatement("update songs set
     sound = ? where id = ?");
stmt.setCustomDatum(1, sound);
stmt.setString(2, id);
stmt.execute( );
stmt.close( );
conn.commit( );




loadAudio(OrdAudio,byte[ ][ ], boolean)

Format

public void loadAudio(oracle.ord.im.OrdAudio media, byte[ ][ ] ctx, boolean setComments)

Description

Loads the uploaded file into an OrdAudio Java object and sets the properties using an application-supplied, format plug-in context. This method loads the audio data into the database and calls the OrdAudio.setProperties( ) method to set the properties, such as the MIME type. The application provides the format plug-in context information and chooses whether or not to set the comments in the OrdAudio object. To use this method, the application fetches an initialized OrdAudio object from the database, calls this method to load the audio data into the database, and then updates the OrdAudio object in the database.

If the call to the setProperties( ) method fails because the audio format is not recognized, this method sets the following properties:

Parameters

media

An oracle.ord.im.OrdAudio object into which the audio data will be loaded.

ctx

The format plug-in context information.

setComments

A Boolean value indicating whether or not to set the comments in the OrdAudio object.

Return Value

None.

Exceptions

java.io.IOException

This exception is thrown if an error occurs while reading or writing the media data.

java.sql.SQLException

This exception is thrown if an unrecognized error occurs while storing the media data.

java.lang.IllegalStateException

This exception is thrown if the uploaded file is no longer available because it has been released.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request);
formData.parseFormData( );
String id = formData.getParameter("id");
OrdHttpUploadFile uploadFile = formData.getFileParameter("soundfile");


OraclePreparedStatement stmt = (OraclePreparedStatement)
     conn.prepareStatement("insert into songs (id,sound) values(?,
     ORDSYS.ORDAUDIO.INIT( ))");
stmt.setString(1, id);
stmt.executeUpdate( );
stmt.close( );


stmt = (OraclePreparedStatement)conn.prepareStatement("select sound from
     songs where id = ? for update");
stmt.setString(1, id);
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (!rset.next( )){
     throw new ServletException("new row not found in table");
}


byte[ ] [ ] ctx = new byte[1][64];
OrdAudio sound = (OrdAudio)rset.getCustomDatum(1, OrdAudio.getFactory( ));
uploadFile.loadAudio(sound, ctx, true);
formData.release( );


rset.close( );
stmt.close( );


stmt = (OraclePreparedStatement)conn.prepareStatement("update songs set
     sound = ? where id = ?");
stmt.setCustomDatum(1, sound);
stmt.setString(2, id);
stmt.execute( );
stmt.close( );
conn.commit( );




loadBlob( )

Format

public void loadBlob(oracle.sql.BLOB blob)

Description

Loads the uploaded media file into a BLOB.

Parameters

blob

An oracle.sql.BLOB into which the data will be loaded.

Return Value

None.

Exceptions

java.io.IOException

This exception is thrown if an error occurs while reading or writing the media data.

java.sql.SQLException

This exception is thrown if an unrecognized error occurs while storing the media data.

java.lang.IllegalStateException

This exception is thrown if the uploaded file is no longer available because it has been released.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request);
formData.parseFormData( );
String id = formData.getParameter("id");
OrdHttpUploadFile uploadFile = formData.getFileParameter("docfile");


OraclePreparedStatement stmt = (OraclePreparedStatement)
     conn.prepareStatement("insert into docs (id,doc_blob) values
     (?,EMPTY_BLOB( ))");
stmt.setString(1, id);
stmt.executeUpdate( );
stmt.close( );


stmt = (OraclePreparedStatement)conn.prepareStatement("select doc_blob
     from docs where id = ? for update" );
stmt.setString(1, id);
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (!rset.next( )){
     throw new ServletException("new row not found in table");
}


BLOB docBlob = rset.getBLOB(1);
uploadFile.loadBlob(docBlob);
formData.release( );


rset.close( );
stmt.close( );
conn.commit( );




loadDoc(OrdDoc)

Format

public void loadDoc(oracle.ord.im.OrdDoc media)

Description

Loads the uploaded file into an OrdDoc Java object and sets the properties based on the contents of the document. This method loads the document into the database and calls the OrdDoc.setProperties( ) method to set the properties, such as the MIME type. This method does not use any existing format plug-in context information and does not set any comments when setting the properties. To use this method, the application fetches an initialized OrdDoc object from the database, calls this method to load the document into the database, and then updates the OrdDoc object in the database.

If the call to the setProperties( ) method fails because the document format is not recognized, this method sets the following properties:

Parameters

media

An oracle.ord.im.OrdDoc object into which the document will be loaded.

Return Value

None.

Exceptions

java.io.IOException

This exception is thrown if an error occurs while reading or writing the media data.

java.sql.SQLException

This exception is thrown if an unrecognized error occurs while storing the media data.

java.lang.IllegalStateException

This exception is thrown if the uploaded file is no longer available because it has been released.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request);
formData.parseFormData( );
String id = formData.getParameter("id");
OrdHttpUploadFile uploadFile = formData.getFileParameter("docfile");


OraclePreparedStatement stmt = (OraclePreparedStatement)
     conn.prepareStatement("insert into documents (id,doc) values(?,
     ORDSYS.ORDDOC.INIT( ))");
stmt.setString(1, id);
stmt.executeUpdate( );
stmt.close( );


stmt = (OraclePreparedStatement)conn.prepareStatement("select doc from
     documents where id = ? for update");
stmt.setString(1, id);
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (!rset.next( )){
     throw new ServletException("new row not found in table");
}


OrdDoc media = (OrdDoc)rset.getCustomDatum(1, OrdDoc.getFactory( ));
uploadFile.loadDoc(media);
formData.release( );


rset.close( );
stmt.close( );


stmt = (OraclePreparedStatement)conn.prepareStatement("update documents set
     doc = ? where id = ?");
stmt.setCustomDatum(1, doc);
stmt.setString(2, id);
stmt.execute( );
stmt.close( );
conn.commit( );




loadDoc(OrdDoc,byte[ ][ ],boolean)

Format

public void loadDoc(oracle.ord.im.OrdDoc media, byte[ ][ ] ctx, boolean setComments)

Description

Loads the uploaded file into an OrdDoc Java object and sets the properties using an application-supplied, format plug-in context. This method loads the document into the database and calls the OrdDoc.setProperties( ) method to set the properties, such as the MIME type. The application provides the format plug-in context information and chooses whether or not to set the comments in the OrdDoc object. To use this method, the application fetches an initialized OrdDoc object from the database, calls this method to load the document into the database, and then updates the OrdDoc object in the database.

If the call to the setProperties( ) method fails because the document format is not recognized, this method sets the following properties:

Parameters

media

An oracle.ord.im.OrdDoc object into which the document will be loaded.

ctx

The format plug-in context information.

setComments

A Boolean value indicating whether or not to set the comments in the object.

Return Value

None.

Exceptions

java.io.IOException

This exception is thrown if an error occurs while reading or writing the media data.

java.sql.SQLException

This exception is thrown if an unrecognized error occurs while storing the media data.

java.lang.IllegalStateException

This exception is thrown if the uploaded file is no longer available because it has been released.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request);
formData.parseFormData( );
String id = formData.getParameter("id");
OrdHttpUploadFile uploadFile = formData.getFileParameter("docfile");


OraclePreparedStatement stmt = (OraclePreparedStatement)
     conn.prepareStatement("insert into documents (id,doc) values(?,
     ORDSYS.ORDDOC.INIT( ))");
stmt.setString(1, id);
stmt.executeUpdate( );
stmt.close( );


stmt = (OraclePreparedStatement)conn.prepareStatement("select doc from
     documents where id = ? for update");
stmt.setString(1, id);
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (!rset.next( )){
     throw new ServletException("new row not found in table");
}


byte[ ] [ ] ctx = new byte[1][64];
OrdDoc media = (OrdDoc)rset.getCustomDatum(1, OrdDoc.getFactory( ));
uploadFile.loadDoc(media, ctx, true);
formData.release( );


rset.close( );
stmt.close( );


stmt = (OraclePreparedStatement)conn.prepareStatement("update documents set
     doc = ? where id = ?");
stmt.setCustomDatum(1, doc);
stmt.setString(2, id);
stmt.execute( );
stmt.close( );
conn.commit( );


loadImage(OrdImage)

Format

public void loadImage(oracle.ord.im.OrdImage media)

Description

Loads the uploaded file into an OrdImage Java object and sets the properties based on the image contents. This method loads the image content into the database and calls the OrdImage.setProperties( ) method to set the image's properties, such as the MIME type, length, height, and width. To use this method, the application fetches an initialized OrdImage object from the database, calls this method to load the image content into the database, and then updates the OrdImage object in the database.

If the call to the setProperties( ) method fails because the image format is not recognized, this method sets the following properties:

Parameters

media

An oracle.ord.im.OrdImage object into which the image data will be loaded.

Return Value

None.

Exceptions

java.io.IOException

This exception is thrown if an error occurs while reading or writing the media data.

java.sql.SQLException

This exception is thrown if an unrecognized error occurs while storing the media data.

java.lang.IllegalStateException

This exception is thrown if the uploaded file is no longer available because it has been released.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request);
formData.parseFormData( );
String id = formData.getParameter("id");
OrdHttpUploadFile uploadFile = formData.getFileParameter("photofile");


OraclePreparedStatement stmt = (OraclePreparedStatement)
     conn.prepareStatement("insert into photos (id,photo) values(?,
     ORDSYS.ORDIMAGE.INIT( ))");
stmt.setString(1, id);
stmt.executeUpdate( );
stmt.close( );


stmt = (OraclePreparedStatement)conn.prepareStatement("select image from
     photos where id = ? for update");
stmt.setString(1, id);
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (!rset.next( )){
     throw new ServletException("new row not found in table");
}


OrdImage photo = (OrdImage)rset.getCustomDatum(1, OrdImage.getFactory( ));
uploadFile.loadImage(photo);
formData.release( );


rset.close( );
stmt.close( );


stmt = (OraclePreparedStatement)conn.prepareStatement("update photos set
     photo = ? where id = ?");
stmt.setCustomDatum(1, photo);
stmt.setString(2, id);
stmt.execute( );
stmt.close( );
conn.commit( );




loadImage(OrdImage,String)

Format

public void loadImage(oracle.ord.im.OrdImage media, String cmd)

Description

Loads the uploaded file into an OrdImage Java object and sets the properties according to an application-supplied command string. To use this method, the application fetches an initialized OrdImage object from the database, calls this method to load the image content into the database, and then updates the OrdImage object in the database.

Parameters

media

An oracle-ord.im.OrdImage object into which the uploaded image data will be loaded.

cmd

A String that specifies the properties to be set.

Return Value

None.

Exceptions

java.io.IOException

This exception is thrown if an error occurs while reading or writing the media data.

java.sql.SQLException

This exception is thrown if an unrecognized error occurs while storing the media data.

java.lang.IllegalStateException

This exception is thrown if the uploaded file is no longer available because it has been released.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request);
formData.parseFormData( );
String id = formData.getParameter("id");
OrdHttpUploadFile uploadFile = formData.getFileParameter("photofile");


OraclePreparedStatement stmt = (OraclePreparedStatement)
     conn.prepareStatement("insert into photos (id,photo) values(?,
     ORDSYS.ORDIMAGE.INIT( ))");
stmt.setString(1, id);
stmt.executeUpdate( );
stmt.close( );


stmt = (OraclePreparedStatement)conn.prepareStatement("select photo from
     photos where id = ? for update");
stmt.setString(1, id);
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (!rset.next( )){
     throw new ServletException("new row not found in table");
}


OrdImage photo = (OrdImage)rset.getCustomDatum(1, OrdImage.getFactory( ));
String cmd = getImagePropertiesCommand(photo);
uploadFile.loadImage(photo, cmd);
formData.release( );


rset.close( );
stmt.close( );


stmt = (OraclePreparedStatement)conn.prepareStatement("update photos set
     photo = ? where id = ?");
stmt.setCustomDatum(1, photo);
stmt.setString(2, id);
stmt.execute( );
stmt.close( );
conn.commit( );




loadVideo(OrdVideo)

Format

public void loadVideo(oracle.ord.im.OrdVideo media)

Description

Loads the uploaded file into an OrdVideo Java object and sets the properties based on the video data. This method loads the video data into the database and calls the OrdVideo.setProperties( ) method to set the properties, such as the MIME type. This method does not use any existing format plug-in context information and does not set any comments when setting the properties. To use this method, the application fetches an initialized OrdVideo object from the database, calls this method to load the video data into the database, and then updates the OrdVideo object in the database.

If the call to the setProperties( ) method fails because the video format is not recognized, this method sets the following properties:

Parameters

media

An oracle.ord.im.OrdVideo object into which the uploaded video data will be loaded.

Return Value

None.

Exceptions

java.io.IOException

This exception is thrown if an error occurs while reading or writing the media data.

java.sql.SQLException

This exception is thrown if an unrecognized error occurs while storing the media data.

java.lang.IllegalStateException

This exception is thrown if the uploaded file is no longer available because it has been released.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request);
formData.parseFormData( );
String id = formData.getParameter("id");
OrdHttpUploadFile uploadFile = formData.getFileParameter("videofile");


OraclePreparedStatement stmt = (OraclePreparedStatement)
    conn.prepareStatement("insert into movies (id,video) values(?,
    ORDSYS.ORDVIDEO.INIT( ))");
stmt.setString(1, id);
stmt.executeUpdate( );
stmt.close( );


stmt = (OraclePreparedStatement)conn.prepareStatement("select video from
    movies where id = ? for update");
stmt.setString(1, id);
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (!rset.next( )){
    throw new ServletException("new row not found in table");
}


OrdVideo media = (OrdVideo)rset.getCustomDatum(1, OrdVideo.getFactory( ));
uploadFile.loadVideo(media);
formData.release( );


rset.close( );
stmt.close( );


stmt = (OraclePreparedStatement)conn.prepareStatement("update movies set
    video = ? where id = ?");
stmt.setCustomDatum(1, video);
stmt.setString(2, id);
stmt.execute( );
stmt.close( );
conn.commit( );




loadVideo(OrdVideo,byte[ ][ ],boolean)

Format

public void loadVideo(oracle.ord.im.OrdVideo media, byte[ ][ ] ctx, boolean setComments)

Description

Loads the uploaded file into an OrdVideo Java object and sets the properties using an application-supplied, format plug-in context. This method loads the video data into the database and calls the OrdVideo.setProperties( ) method to set the properties, such as the MIME type. The application provides the format plug-in context information and chooses whether or not to set the comments in the OrdVideo object. To use this method, the application fetches an initialized OrdVideo object from the database, calls this method to load the video data into the database, and then updates the OrdVideo object in the database.

If the call to the setProperties( ) method fails because the video format is not recognized, this method sets the following properties:

Parameters

media

An oracle.ord.im.OrdVideo object into which the uploaded video data will be loaded.

ctx

The format plug-in context information.

setComments

A Boolean value indicating whether or not to set the comments in the object.

Return Value

None.

Exceptions

java.io.IOException

This exception is thrown if an error occurs while reading or writing the media data.

java.sql.SQLException

This exception is thrown if an unrecognized error occurs while storing the media data.

java.lang.IllegalStateException

This exception is thrown if the uploaded file is no longer available because it has been released.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request);
formData.parseFormData( );
String id = formData.getParameter("id");
OrdHttpUploadFile uploadFile = formData.getFileParameter("videofile");


OraclePreparedStatement stmt = (OraclePreparedStatement)
     conn.prepareStatement("insert into movies (id,video) values(?,
     ORDSYS.ORDVIDEO.INIT( ))");
stmt.setString(1, id);
stmt.executeUpdate( );
stmt.close( );


stmt = (OraclePreparedStatement)conn.prepareStatement("select video from
     movies where id = ? for update");
stmt.setString(1, id);
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (!rset.next( )){
     throw new ServletException("new row not found in table");
}


byte[ ] [ ] ctx = new byte[1][64];
OrdVideo media = (OrdVideo)rset.getCustomDatum(1, OrdVideo.getFactory( ));
uploadFile.loadVideo(media, ctx, true);
formData.release( );


rset.close( );
stmt.close( );


stmt = (OraclePreparedStatement)conn.prepareStatement("update movies set
     video = ? where id = ?");
stmt.setCustomDatum(1, video);
stmt.setString(2, id);
stmt.execute( );
stmt.close( );
conn.commit( );




release( )

Format

public void release( )

Description

Releases all resources held by an OrdHttpUploadFile object. Specifically, this method releases the memory used to hold the contents of an uploaded file or deletes the temporary file used to hold the contents of the uploaded file. An application can optimize memory usage by calling this method to release any allocated memory, making it a candidate for garbage collection, after the application has finished processing an uploaded file.

Parameters

None.

Return Value

None.

Exceptions

None.

Examples

See getContentLength( ) for an example of this method.




OrdHttpUploadFormData Reference Information

This section presents reference information on the methods of the OrdHttpUploadFormData class.

File uploading using HTML forms encodes form data and uploaded files in POST requests using the multipart/form-data format. The OrdHttpUploadFormData class facilitates the processing of such requests by parsing the POST data and making the contents of regular form fields and uploaded files readily accessible to a Java servlet or JavaServer Page (JSP). The OrdHttpUploadFormData class provides methods to access text-based form field parameters that are identical to the getParameter( ), getParameterValues( ), and getParameterNames( ) methods provided by the ServletRequest class. Access to uploaded files is provided by a similar set of methods, namely getFileParameter( ), getFileParameterValues( ), and getFileParameterNames( ). The OrdHttpUploadFile objects returned by the getFileParameter( ) and getFileParameterValues( ) methods provide simple access to the MIME type, length, and contents of each uploaded file.

For more information on the OrdHttpUploadFile class, see OrdHttpUploadFile Reference Information.

The following is an example of how to use the OrdHttpUploadFormData class:

// Create an OrdHttpUploadFormData object and use it to parse the
// multipart/form-data message.
//
OrdHttpUploadFormData formData = new OrdHttpUploadFormData( request );
formData.parseFormData( );


// Get the description, location, and photograph.
//
String id = formData.getParameter("id");
String description = formData.getParameter("description");
String location = formData.getParameter("location");
OrdHttpUploadFile photo = formData.getFileParameter("photo");


// Prepare and execute a SQL statement to insert a new row into
// the table and return the sequence number for the new row.
// Disable auto-commit to allow the LOB to be written correctly.
//
conn.setAutoCommit(false);
PreparedStatement stmt = conn.prepareStatement("insert into photo_album (id, 
     description, location, photo) " + " values (?, ?, ?, ORDSYS.ORDIMAGE.INIT( ))");
stmt.setString(1, id);
stmt.setString(2, description);
stmt.setString(3, location);
stmt.executeUpdate( );


// Prepare and execute a SQL statement to fetch the new OrdImage
// object from the database.
//
stmt = conn.prepareStatement("select photo from photo_album where id = ? for 
     update");
stmt.setString(1, id);
OracleResultSet rset = (OracleResultSet)stmt.executeQuery( );
if (!rset.next( )){
     throw new ServletException("new row not found in table");
}
OrdImage media = (OrdImage)rset.getCustomDatum(1, OrdImage.getFactory( ));


// Load the photograph into the database and set the properties.
//
photo.loadImage(media);


// Prepare and execute a SQL statement to update the image object.
//
stmt = (OraclePreparedStatement)conn.prepareStatement("update photo_album set 
     photo = ? where id = ?");
stmt.setCustomDatum(1, media);
stmt.setString(2 id);
stmt.execute( );
stmt.close( );


// Commit the changes.
//
conn.commit( );
A Note on the Handling of Query String Parameters and Text-Based HTML Form Field Parameters

Every parameter in the optional query string of a request produces a corresponding parameter of type String, whether or not any data is associated with the parameter name. Likewise, every text-based input field in an HTML form also produces a corresponding parameter of type String, whether or not any data is entered into a field. When processing query string parameters and text-based input fields, applications can test the length of the corresponding String object to determine if any data is present.

The parseFormData( ) method merges all query string and form field parameters into a single set of ordered parameters, where the query string parameters are processed first, followed by the form field parameters. Thus, query string parameters take precedence over form field parameters. For example, if a request is made with a query string of arg=hello&arg=world and the values 'greetings' and 'everyone' are entered into two HTML form fields named 'arg', then the resulting parameter set would include the following entry: arg=(hello, world, greetings, everyone).

A Note on the Handling of FILE-Type HTML Form Field Parameters

Every input field of type FILE in an HTML form produces a corresponding parameter of type OrdUploadFile, whether or not a valid file name is entered into the field. When processing a field of type FILE, applications can test either the length of the file name, the length of content, or a combination of the two to determine if a valid file name was entered by a user, and if the file was successfully uploaded by the browser. See the OrdHttpUploadFile class in OrdHttpUploadFile Reference Information for more information.

A Note on the Use of Non-Western European Languages

Microsoft's Internet Explorer browser allows data to be entered into an HTML form using a character set encoding that is different from that being used to view the form. For example, it is possible to copy Japanese Shift_JIS character set data from one browser window and paste it into a form being viewed using the Western European (ISO) character set in a different browser window. In this situation, Internet Explorer can sometimes transmit the form data twice in such a way that the multipart/form-data parser cannot detect the duplicated data. Furthermore, the non-Western European language form data is sometimes sent as a Unicode escape sequence, sometimes in its raw binary form, and sometimes duplicated using both formats in different portions of the POST data.

Although this same problem does not exist with the Netscape browser, care must still be taken to ensure that the correct character set is being used. For example, although it is possible to copy Japanese Shift_JIS character set data from one browser window and paste it into a form being viewed using the Western European (ISO) character set in a different browser window, when the data is pasted into the form field, the two bytes that comprise each Japanese Shift_JIS character are stored as two individual Western European (ISO) characters.

Therefore, care must be taken to view an HTML form using the correct character set, no matter which Web browser is used. For example, the HTML META tag can be used to specify the character set as follows:

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=Shift_JIS">


enableParameterTranslation( )

Format

public void enableParameterTranslation(java.lang.Sting encoding)

Description

Enables the translation of all HTML form parameter names and all text-based HTML form parameter values using the specified character encoding when parsing the body of a multipart/form-data POST request.

Character encoding of request parameters is not well defined in the HTTP specification. Most servlet containers interpret them using the servlet default encoding, ISO-8859-1. Therefore, to provide an API that is compatible with such servlet containers, by default, the OrdHttpUploadFormData class also interprets multipart/form-data request parameters using the default encoding, ISO-8859-1.

Applications that process requests and responses using other character encodings can, prior to calling the parseFormData( ) method, call the enableParameterTranslation( ) method to specify the character encoding to be used to translate the names of all HTML form parameters, and the values of all text-based HTML form parameters when parsing the body of a multipart/form-data POST request.


Notes:

  • Query string parameters that accompany multipart/form-data POST requests are not translated prior to being merged into the list of multipart/form-data parameters. This is because there is no way to determine if the underlying servlet container or JSP engine has decoded the query string or translated the parameter names and values already. Therefore, the application is responsible for translating any multibyte query string parameter names or values in the case where the underlying servlet container or JSP engine does not perform the translation.

  • The contents of uploaded files are never translated; nor is the associated content type attribute, which is always represented using the ISO-8859-1 character encoding. However, the file name attribute of an uploaded file is translated.

  • Query string parameters in GET requests and query string and POST data parameters in application/x-www-form-urlencoded POST requests are never translated.

  • To correctly handle the translation of HTML form parameter names and values, applications must call the enableParameterTranslation( ) method for multipart/form-data POST requests, even if the servlet container or JSP engine translates parameter names and values for GET requests and application/x-www-form-urlencoded POST requests.

  • Do not call the enableParameterTranslation( ) method if the application contains code that handles the translation of parameter names and values.

  • The enableParameterTranslation( ) method must be called before calling the parseFormData( ) method.


Calling the enableParameterTranslation( ) method with a character encoding other than ISO-8859-1 affects the following methods when called for multipart/form-data POST requests:

For GET requests and application/x-www-form-urlencoded POST requests, calls to the getParameter( ), getParameterValues( ), and getParameterNames( ) methods are passed directly to the underlying servlet container or JSP engine. Please consult the servlet container or JSP engine documentation for information regarding any parameter translation functions that might be supported by the servlet container or JSP engine.

Parameters

encoding

A String that specifies the character encoding.

Return Value

None.

Exceptions

None.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request);
formData.enableParameterTranslation("GB2312")
formData.parseFormData( );




getFileParameter( )

Format

public OrdHttpUploadFile getFileParameter(String parameterName)

Description

Returns information about an uploaded file identified by parameter name, as an OrdHttpUploadFile object.

Every input field of type FILE in an HTML form will produce a parameter of type OrdHttpUploadFile, whether or not you enter a valid file name into the field.

Parameters

parameterName

The name of the uploaded file parameter, as a String.

Return Value

This method returns the uploaded file parameter, as an OrdHttpUploadFile object, or null if the parameter does not exist.

Exceptions

java.lang.IllegalStateException

This exception is thrown if the ServletRequest object has not been specified, if the multipart form data has not been parsed, or if the upload request has been released.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request);
formData.parseFormData( );
...
OrdHttpUploadFile photo = formData.getFileParameter("photo");
photo.loadImage(media);
...
formData.release( );



getFileParameterNames( )

Format

public java.util.Enumeration getFileParameterNames( )

Description

Returns an Enumeration of the names of all input fields of type FILE in an HTML form, or an empty Enumeration if there are no input fields of type FILE.

Every input field of type FILE in an HTML form will produce a parameter of type OrdHttpUploadFile, whether or not you enter a valid file name into the field.

Parameters

None.

Return Value

This method returns a list of uploaded file parameter names, as an Enumeration of Strings.

Exceptions

java.lang.IllegalStateException

This exception is thrown if the ServletRequest object has not been specified, if the multipart form data has not been parsed, or if the upload request has been released.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData( request );
formData.parseFormData( );
...
Enumeration names = formData.getFileParameterNames( );


getFileParameterValues( )

Format

public OrdHttpUploadFile[ ] getFileParameterValues(String parameterName)

Description

Returns an array of OrdHttpUploadFile objects that represent all files uploaded using the specified parameter name. Every input field of type FILE in an HTML form will produce a parameter of type OrdHttpUploadFile, whether or not you enter a valid file name in the field.

Parameters

parameterName

The name of the uploaded file parameter, as a String.

Return Value

This method returns the uploaded file parameters as an array of OrdHttpUploadFile objects, or null if the parameter does not exist.

Exceptions

java.lang.IllegalStateException

This exception is thrown if the ServletRequest object has not been specified, if the multipart form data has not been parsed, or if the upload request has been released.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData( request );
formData.parseFormData( );
...
OrdHttpUploadFile[ ] photo = formData.getFileParameterValues("photo")




getParameter( )

Format

public String getParameter(String parameterName)

Description

Returns the value of the first query string parameter or text-based form field parameter with the specified name, or null if the parameter does not exist. The query string parameters of the request are merged with the text-based form field parameters by the parseFormData( ) method.

This method calls the getParameterName( ) method in the ServletRequest class if the request is not a multipart/form-data upload request.

Parameters

parameterName

A String that specifies the parameter name.

Return Value

This method returns the value of the specified parameter, as a String, or null if the parameter does not exist.

Exceptions

java.lang.IllegalStateException

This exception is thrown if the ServletRequest object has not been specified, if the multipart form data has not been parsed, or if the upload request has been released.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData( request );
formData.parseFormData( );
...
String id = formData.getParameter("id");




getParameterNames( )

Format

public java.util.Enumeration getParameterNames( )

Description

Returns an Enumeration of all the query string parameter names and all the text-based form field data parameter names in the request, or an empty Enumeration if there are no query string parameters and no text-based form field parameters. The query string parameters of the request are merged with the text-based form field parameters by the parseFormData( ) method.

This method calls the getParameterNames( ) method in the ServletRequest class if the request is not a multipart/form-data upload request.

Parameters

None.

Return Value

This method returns a list of parameter names, as an Enumeration of Strings.

Exceptions

java.lang.IllegalStateException

This exception is thrown if the ServletRequest object has not been specified, if the multipart form data has not been parsed, or if the upload request has been released.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData( request );
formData.parseFormData( );
...
Enumeration names = formData.getParameterNames( );




getParameterValues( )

Format

public String[ ] getParameterValues(String parameterName)

Description

Returns an array of String objects containing the values of all the query string parameters and text-based form field data parameters with the specified parameter name, or null if the parameter does not exist. The query string parameters of the request are merged with the text-based form field parameters by the parseFormData( ) method.

This method calls the getParameterValues( ) method in the ServletRequest class if the request is not a multipart/form-data upload request.

Parameters

parameterName

A String that specifies the parameter name.

Return Value

This method returns the parameter value, as a String, or null if the parameter does not exist.

Exceptions

java.lang.IllegalStateException

This exception is thrown if the ServletRequest object has not been specified, if the multipart form data has not been parsed, or if the upload request has been released.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request);
formData.parseFormData( );
...
String[ ] ids = formData.getParameterValues("id");




isUploadRequest( )

Format

public boolean isUploadRequest( )

Description

Tests if the request was encoded using the multipart/form-data encoding format.

Parameters

None.

Return Value

This method returns true if the request body was encoded using the multipart/form-data encoding format; false otherwise.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest has not been specified.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request);
if(formData.isUploadRequest( )){
     formData.parseFormData( );
     OrdHttpUploadFile uploadFile = formData.getFileParameter(...);
     ...
}
else{
     String param = request.getParameter(...);
     ...
}


OrdHttpUploadFormData( )

Format

public OrdHttpUploadFormData( )

Description

Creates an OrdHttpFormData object to parse a multipart/form-data request. Subsequently, the application must specify the ServletRequest object.

Parameters

None.

Return Value

None.

Exceptions

None.

Examples

See setServletRequest( ) for an example of this method.


OrdHttpUploadFormData(ServletRequest)

Format

public OrdHttpUploadFormData(javax.servlet.ServletRequest request)

Description

Creates an OrdHttpUploadFormData object to parse a multipart/form-data request.

Parameters

request

An object of type ServletRequest.

Return Value

None.

Exceptions

None.

Examples

See getFileParameter( ) for an example of this method.


parseFormData( )

Format

public void parseFormData( )

Description

Parses the body of a POST request that is encoded using the multipart/form-data encoding. If the request is not an upload request, this method does nothing.

Parameters

None.

Return Value

None.

Exceptions

java.lang.IllegalStateException

This exception is thrown if HttpServletRequest has not been specified.

java.io.IOException

This exception is thrown if an error occurs reading the request body or writing a temporary file.

OrdHttpUploadException

This exception is thrown if an error occurs parsing the multipart/form-data message.

Examples

See getFileParameter( ) for an example of this method.


release( )

Format

public void release( )

Description

Releases all resources held by an OrdHttpUploadFormData object, including temporary files used to hold the contents of uploaded files. An application that enables the use of temporary files must call this method.

Parameters

None.

Return Value

None.

Exceptions

None.

Examples

See getFileParameter( ) for an example of this method.


setMaxMemory( )

Format

public void setMaxMemory(int maxMemory, String tempFileDir)

Description

Specifies the maximum amount of memory that the contents of uploaded files can consume before the contents are stored in a temporary directory.

By default, the contents of uploaded files are held in memory until stored in a database by the application. If users upload large files, such as large video clips, then it may be desirable to limit the amount of memory consumed, and to store temporarily the contents of such files on disk, before the contents are written to a database.


Note:

Applications that use this mechanism must ensure that any temporary files are deleted when no longer required by using the release( ) method. See the release( ) method for more information.

Parameters

maxMemory

An integer that specifies the maximum amount of memory to be consumed by all uploaded files in a request before the contents of the uploaded files are stored in temporary files.

tempFileDir

A String that specifies the temporary file directory where you will store temporary files. This parameter is optional if the java.io.tmpdir system property is present.

Return Value

None.

Exceptions

java.lang.IllegalArgumentException

This exception is thrown if the maxMemory parameter is negative, or if the tempFileDir parameter was specified as null and the java.io.tmpdir system property is not present.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request);
try{
     formData.setMaxMemory(65536,null);
     formData.parseFormData( );
     ...
     OrdHttpUploadFile photo = formData.getFileParameter("photo");
     photo.loadImage(media);
     ...
}
finally{
     formData.release( );
}


setServletRequest( )

Format

public void setServletRequest(javax.servlet.ServletRequest request)

Description

Specifies the ServletRequest object for the request. The ServletRequest object must be specified either in the constructor, or by calling this method before parsing the request.

Parameters

request

An object of type ServletRequest.

Return Value

None.

Exceptions

None.

Examples

OrdHttpUploadFormData formData = new OrdHttpUploadFormData( );
...
formData.setServletRequest(request);






Previous Next
Oracle Logo
Copyright © 1999, 2002 Oracle Corporation

All rights reserved
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback