Oracle interMedia Java Classes User's Guide and Reference
Release 9.0.1

Part Number A88785-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

Go to previous page Go to next page

9
Java Classes for Servlets and JSPs Reference Information

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

The OrdHttpResponseHandler class facilitates the retrieval of multimedia 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 JSPs.

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 a Java servlet 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 multimedia data into an Oracle 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.*;

9.2 OrdHttpResponseHandler Reference Information

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

This class extends java.lang.Object.

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 img = (OrdImage)rset.getCustomDatum(1, OrdImage.getFactory( ));
     OrdHttpResponseHandler handler = new OrdHttpResponseHandler(request,
          response);
     handler.sendImage(img);
}
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 an OrdDoc object contains a text-based document that uses a character set (or charset) other than ISO-8859-1 (also called Latin-1) and you want to retrieve the document and deliver it 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 of 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 use 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 the 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( ));
     return;
}
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 with the setServletRequest( ) method, and can optionally specify the HttpServletRequest object with the setServletRequest( ) method.

Parameters

None.

Return Value

None.

Exceptions

None.

Example

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 specifying the HttpServletRequest and HttpServletResponse objects.

Parameters

request

The HttpServletRequest object for this request.

response

The HttpServletResponse object for this request.

Return Value

None.

Exceptions

None.

Example

See sendAudio( ) for an example of this method.


sendAudio( )

Format

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

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

audio

The OrdAudio object whose contents will be delivered to the browser.

Return Value

None.

Exceptions

java.io.IOException - if an error occurs reading the audio data

java.lang.IllegalStateException - if HttpServletRequest or HttpServletResponse has not been specified

java.sql.SQLException - if an error occurs obtaining an InputStream to read the audio data

javax.servlet.ServletException - if an error occurs accessing the binary output stream

OrdHttpResponseException - if the source type is not recognized

Example

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


sendDoc( )

Format

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

Description

Retrieves multimedia 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

doc

The OrdDoc object whose contents will be delivered to the browser.

Return Value

None.

Exceptions

java.io.IOException - if an error occurs reading the multimedia data

java.lang.IllegalStateException - if HttpServletRequest or HttpServletResponse has not been specified

java.sql.SQLException - if an error occurs obtaining an InputStream to read the multimedia data

javax.servlet.ServletException - if an error occurs accessing the binary output stream

OrdHttpResponseException - if the source type is not recognized

Example

OraclePreparedStatement stmt = (OraclePreparedStatement)
     conn.prepareStatement("select doc 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( ));
     OrdHttpResponseHandler handler = new OrdHttpResponseHandler
          (request, response);
     handler.sendDoc(doc);
     return;
}
else{
     response.setStatus(response.SC_NOT_FOUND);
}


sendImage( )

Format

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

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

image

The OrdImage object whose contents will be delivered to the browser.

Return Value

None.

Exceptions

java.io.IOException - if an error occurs reading the image data

java.lang.IllegalStateException - if HttpServletRequest or HttpServletResponse has not been specified

java.sql.SQLException - if an error occurs obtaining an InputStream to read the image data

javax.servlet.ServletException - if an error occurs accessing the binary output stream

OrdHttpResponseException - if the source type is not recognized

Example

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 image = (OrdImage)rset.getCustomDatum(1, OrdImage.getFactory( ));
     OrdHttpResponseHandler handler = new OrdHttpResponseHandler
          (request, response);
     handler.sendImage(image);
     return;
}
else{
     response.setStatus(response.SC_NOT_FOUND);
}


sendResponse(String,int,BFILE,Timestamp)

Format

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

Description

Builds an 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

The MIME type of the content.

length

The length of the data.

bfile

The BFILE from which the multimedia data is retrieved.

lastModified

A Timestamp object that specifies the date and time when the data was last modified. Specify null if a Timestamp with the last modified date is not available.

Return Value

None.

Exceptions

java.io.IOException - if an error occurs reading the multimedia data

java.lang.IllegalArgumentException - if the length is negative

java.lang.IllegalStateException - if HttpServletRequest or HttpServletResponse has not been specified

java.sql.SQLException - if an error occurs obtaining an InputStream to read the multimedia data

javax.servlet.ServletException - if an error occurs accessing the binary output stream

Example

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 an 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

The MIME type of the content.

length

The length of the data.

blob

The BLOB from which the multimedia data is retrieved.

lastModified

A Timestamp object that specifies the date and time when the data was last modified. Specify null if a Timestamp with the last modified date is not available.

Return Value

None.

Exceptions

java.io.IOException - if an error occurs reading the multimedia data

java.lang.IllegalArgumentException - if the length is negative

java.lang.IllegalStateException - if HttpServletRequest or HttpServletResponse has not been specified

java.sql.SQLException - if an error occurs obtaining an InputStream to read the multimedia data

javax.servlet.ServletException - if an error occurs accessing the binary output stream

Example

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 an HTTP response header, then retrieves the contents of the InputStream and delivers it to the browser.

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

Parameters

contentType

The MIME type of the content.

length

The length of the data.

in

The InputStream object from which the multimedia data is retrieved.

lastModified

A Timestamp object that specifies the date and time when the data was last modified. Specify null if a Timestamp with the last modified date is not available.

Return Value

None.

Exceptions

java.lang.IllegalStateException - if HttpServletRequest or HttpServletResponse has not been specified

java.lang.IllegalArgumentException - if the length is negative

javax.servlet.ServletException - if an error occurs accessing the binary output stream

java.io.IOException - if an error occurs reading the multimedia data

Example

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

The length of the data.

bfile

The BFILE from which the multimedia data is retrieved.

Return Value

None.

Exceptions

java.lang.IllegalStateException - if HttpServletRequest has not been specified

java.lang.IllegalArgumentException - if the length is negative

javax.servlet.ServletException - if an error occurs accessing the binary output stream

java.sql.SQLException - if an error occurs obtaining an InputStream to read the multimedia data

java.io.IOException - if an error occurs reading the multimedia data

Example

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

The length of the data.

blob

The BLOB from which the multimedia data is retrieved.

Return Value

None.

Exceptions

java.lang.IllegalStateException - if HttpServletRequest has not been specified

java.lang.IllegalArgumentException - if the length is negative

javax.servlet.ServletException - if an error occurs accessing the binary output stream

java.sql.SQLException - if an error occurs obtaining an InputStream to read the multimedia data

java.io.IOException - if an error occurs reading the multimedia data

Example

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 and delivers it as the response body to the browser. The caller is responsible for building the HTTP header.

Parameters

length

The length of the data.

in

The InputStream object from which the multimedia data is retrieved.

Return Value

None.

Exceptions

java.lang.IllegalStateException - if HttpServletRequest has not been specified

java.lang.IllegalArgumentException - if the length is negative

javax.servlet.ServletException - if an error occurs accessing the binary output stream

java.io.IOException - if an error occurs reading the multimedia data

Example

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 video)

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

video

The OrdVideo object whose contents will be delivered to the browser.

Return Value

None.

Exceptions

java.lang.IllegalStateException - if HttpServletRequest or HttpServletResponse has not been specified

OrdHttpResponseException - if the source type is not recognized

javax.servlet.ServletException - if an error occurs accessing the binary output stream

java.sql.SQLException - if an error occurs obtaining an InputStream to read the video data

java.io.IOException - if an error occurs reading the video data

Example

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 video = (OrdVideo)rset.getCustomDatum(1, OrdVideo.getFactory( ));
     OrdHttpResponseHandler handler = new OrdHttpResponseHandler
          (request, response);
     handler.sendVideo(video);
     return;
}
else{
     response.setStatus( response.SC_NOT_FOUND );
}


setBufferSize( )

Format

public void setBufferSize(int bufferSize)

Description

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

Parameters

bufferSize

The buffer size to be set.

Return Value

None.

Exceptions

java.lang.IllegalArgumentException - if the buffer size is negative or zero

Example

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 request. You must call this method if you did not set the HttpServletRequest object in the constructor and you want to use any of the send methods other than the sendResponseBody methods; you do not need to set the HttpServletRequest object if you use only the sendResponseBody methods.

Parameters

request

The HttpServletRequest object to set for this request.

Return Value

None.

Exceptions

None.

Example

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


setServletResponse( )

Format

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

Description

Sets the HttpServletResponse object for this request. You must call this method if you did not set the HttpServletResponse object in the constructor.

Parameters

response

The HttpServletResponse object to set for this request.

Return Value

None.

Exceptions

None.

Example

See setServletRequest( ) for an example of this method.

9.3 OrdHttpJspResponseHandler Reference Information

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

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

The methods provided by this class that deliver multimedia data all use the JspWriter.clear method to clear the page output buffer prior to delivering the media data; therefore, the page must use the buffered output model, which is the default.

This class extends OrdHttpResponseHandler.

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 following the image.

<%@ 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;
     }
%>
An Important Note on JSP Engines

JSP engines do not have to support access to the servlet binary output stream. Therefore, not all JSP engines support the delivery of multimedia data using the OrdHttpJspResponseHandler class.

All multimedia data stored in the database using interMedia objects, including text documents stored in OrdDoc objects, is stored using a binary LOB data type. Multimedia data that is stored internally in the database is stored using a BLOB. Multimedia data that is stored in an operating system file outside the database is stored using a BFILE. Therefore, all multimedia 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 by calling 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 with a JSP. A JSP engine that does not support this usage typically throws an IllegalStateException from the getOutputStream( ) method. However, the exact behavior is specific to the implementation used.

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 multimedia data. For example, perform one of the following operations:

A Note on Return Statements

When delivering multimedia 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 data other than the multimedia data is written to the output stream associated with the JSP.

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. This construct, which mirrors the code produced by some JSP engines to handle the <jsp:forward...> directive, is illustrated in the previous example.


OrdHttpJspResponseHandler( )

Format

public OrcHttpJspResponseHandler( )

Description

Creates an OrdHttpJspResponseHandler object to handle the response to a multimedia retrieval request. The application must subsequently specify the PageContent object.

Parameters

None.

Return Value

None.

Exceptions

None.

Example

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 specifying the PageContext object.

Parameters

pageContext

The PageContext object for the request.

Return Value

None.

Exceptions

None.

Example

OrdHttpJspResponseHandler handler = new OrdHttpJspResponseHandler(pageContext);


sendAudio( )

Format

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

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 image. Therefore, the page must use the buffered output model, which is the default.

Parameters

audio

The OrdAudio object whose contents will be delivered to the browser.

Return Value

None.

Exceptions

java.io.IOException - if an error occurs reading the audio data

java.lang.IllegalStateException - if PageContext has not been specified

java.sql.SQLException - if an error occurs obtaining an InputStream to read the data

OrdHttpResponseException - if the source type is not recognized

javax.servlet.ServletException - if an error occurs accessing the binary output stream

Example

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


sendDoc( )

Format

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

Description

Retrieves multimedia 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 image. Therefore, the page must use the buffered output model, which is the default.

Parameters

doc

The OrdDoc object whose contents will be delivered to the browser..

Return Value

None.

Exceptions

java.io.IOException - if an error occurs reading the multimedia data

java.lang.IllegalStateException - if PageContext has not been specified

java.sql.SQLException - if an error occurs obtaining an InputStream to read the data

OrdHttpResponseException - if the source type is not recognized

javax.servlet.ServletException - if an error occurs accessing the binary output stream

Example

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


sendImage( )

Format

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

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

image

An OrdImage object whose contents will be delivered to the browser..

Return Value

None.

Exceptions

java.io.IOException - if an error occurs reading the image data

java.lang.IllegalStateException - if PageContext has not been specified

java.sql.SQLException - if an error occurs obtaining an InputStream to read the data

OrdHttpResponseException - if the source type is not recognized

javax.servlet.ServletException - if an error occurs accessing the binary output stream

Example

The OrdHttpJspResponseHandler.sendImage( ) method extends the OrdHttpResponseHandler.sendImage( ) method. See sendImage( ) in Section 9.2 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 an HTTP response header and 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

The MIME type of the contents.

length

The length of the data.

bfile

The BFILE whose contents will be delivered to the browser.

lastModified

A Timestamp object that specifies the date and time when the data was last modified. Specify null if a Timestamp with the last modified date is not available.

Return Value

None.

Exceptions

java.io.IOException - if an error occurs reading the multimedia data

java.lang.IllegalArgumentException - if the length is negative

java.lang.IllegalStateException - if PageContext has not been specified

java.sql.SQLException - if an error occurs obtaining an InputStream to read the multimedia data

javax.servlet.ServletException - if an error occurs accessing the binary output stream

Example

The OrdHttpJspResponseHandler.sendResponse(String, int, BFILE, Timestamp) method extends the OrdHttpResponseHandler.sendResponse(String, int, BFILE, Timestamp) method. See sendResponse(String,int,BFILE,Timestamp) in Section 9.2 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 an HTTP response header and 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

The MIME type of the contents.

length

The length of the data.

blob

The BLOB whose contents will be delivered to the browser.

lastModified

A Timestamp object that specifies the date and time when the data was last modified. Specify null if a Timestamp with the last modified date is not available.

Return Value

None.

Exceptions

java.io.IOException - if an error occurs reading the multimedia data

java.lang.IllegalArgumentException - if the length is negative

java.lang.IllegalStateException - if PageContext has not been specified

java.sql.SQLException - if an error occurs obtaining an InputStream to read the multimedia data

javax.servlet.ServletException - if an error occurs accessing the binary output stream

Example

The OrdHttpJspResponseHandler.sendResponse(String, int, BLOB, Timestamp) method extends the OrdHttpResponseHandler.sendResponse(String, int, BLOB, Timestamp) method. See sendResponse(String,int,BLOB,Timestamp) in Section 9.2 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 an HTTP response header and retrieves the contents of the InputStream 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

The MIME type of the contents.

length

The length of the data.

in

The InputStream whose contents will be delivered to the browser.

lastModified

A Timestamp object that specifies the date and time when the data was last modified. Specify null if a Timestamp with the last modified date is not available.

Return Value

None.

Exceptions

java.io.IOException - if an error occurs reading the multimedia data

java.lang.IllegalArgumentException - if the length is negative

java.lang.IllegalStateException - if PageContext has not been specified

java.sql.SQLException

javax.servlet.ServletException - if an error occurs accessing the binary output stream

Example

The OrdHttpJspResponseHandler.sendResponse(String, int, InputStream, Timestamp) method extends the OrdHttpResponseHandler.sendResponse(String, int, InputStream, Timestamp) method.

See sendResponse(String,int,InputStream,Timestamp) in Section 9.2 for an example of this method in the base class.


sendVideo( )

Format

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

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 image. Therefore, the page must use the buffered output model, which is the default.

Parameters

video

The OrdVideo object whose contents will be delivered to the browser.

Return Value

None.

Exceptions

java.io.IOException - if an error occurs reading the video data

java.lang.IllegalStateException - if PageContext has not been specified

java.sql.SQLException - if an error occurs obtaining an InputStream to read the data

OrdHttpResponseException - if the source type is not recognized

javax.servlet.ServletException - if an error occurs accessing the binary output stream

Example

The OrdHttpJspResponseHandler.sendVideo( ) method extends the OrdHttpResponseHandler.sendVideo( ) method. See sendVideo( ) in Section 9.2 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 request. You must call this method if you did not set the PageContext object in the constructor.

Parameters

pageContext

The PageContext object for this request.

Return Value

None.

Exceptions

None.

Example

<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 image = (OrdImage)rset.getCustomDatum(1,
               OrdImage.getFactory( ));
          handler.setPageContext(pageContext);
          handler.sendImage(image);
          return;
     }else{
          response.setStatus(response.SC_NOT_FOUND);
     }
%>

9.4 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. 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 Section 9.5.

This class extends java.lang.Object.

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 photo.
//
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 image = (OrdImage)rset.getCustomDatum(1, OrdImage.getFactory( ));

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

// 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, image);
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, ordered parameter set, 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 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 a field of type FILE. 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 Section 9.5 for more information.

A Note on the Use of Non-Western European Languages

Microsoft's Internet Explorer (IE) 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 Simplified Chinese (GB2312) 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, IE 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 Simplified Chinese (GB2312) 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 Simplified Chinese 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=GB2312">

enableParameterTranslation( )

Format

public void enableParameterTranslation(java.lang.Sting encoding)

Description

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

Prior to calling the parseFormData( ) method, applications that process requests and responses using character encodings other than ISO-8859-1 can 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.

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.

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

The character encoding to be used.

Return Value

None.

Exceptions

None.

Example

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 the given 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 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 - 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

Example

OrdHttpUploadFormData formData = new OrdHttpUploadFormData(request);
formData.parseFormData( );
...
OrdHttpUploadFile photo = formData.getFileParameter("photo");
photo.loadImage(image);
...
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, or an empty Enumeration if there are no input fields of type FILE.

Exceptions

java.lang.IllegalStateException - 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

Example

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 - 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

Example

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

The name of the parameter whose value you want to get.

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 - 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

Example

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 POST data parameter names in the request, or an empty Enumeration if there are no text-based 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 this is not a multipart/form-data upload request.

Parameters

None.

Return Value

This method returns a list of text-based parameter names, as an Enumeration of String objects, or an empty Enumeration if there are no text-based parameters.

Exceptions

java.lang.IllegalStateException - 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

Example

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 POST 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 not a multipart/form-data upload request.

Parameters

parameterName

The name of the parameter.

Return Value

This method returns an array of String objects containing the parameter values, or null if the parameter does not exist.

Exceptions

java.lang.IllegalStateException - 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

Example

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


isUploadRequest( )

Format

public boolean isUploadRequest( )

Description

Checks 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 - if HttpServletRequest has not been specified

Example

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. The application must subsequently specify the ServletRequest object with the setServletRequest( ) method.

Parameters

None.

Return Value

None.

Exceptions

None.

Example

See setServletRequest( ) for an example of this method.


OrdHttpUploadFormData(ServletRequest)

Format

public OrdHttpUploadFormData(javax.servlet.ServletRequest request)

Description

Creates an OrdHttpUploadFormData object using the specified ServletRequest object.

Parameters

request

The ServletRequest object from which the multipart/form-data request will be read.

Return Value

None.

Exceptions

None.

Example

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.io.IOException - if an error occurs reading the request body or writing a temporary file

java.lang.IllegalStateException - if HttpServletRequest has not been specified

OrdHttpUploadException - if an error occurs parsing the multipart/form-data message

Example

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 uses temporary files must use this method.

Parameters

None.

Return Value

None.

Exceptions

None.

Example

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 temporary files.

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.

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

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

The directory where you will store temporary files. This parameter is optional if the java.io.tmpdir system property has been set.

Return Value

None.

Exceptions

java.lang.IllegalArgumentException - if maxMemory is negative, or if tempFileDir was specified as null and the java.io.tmpdir system property is not present

Example

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

setServletRequest( )

Format

public void setServletRequest(javax.servlet.ServletRequest request)

Description

Specifies the ServletRequest object for the request. If you did not set the ServletRequest object in the constructor, you must set it with this method before parsing the request.

Parameters

request

The ServletRequest object to be set.

Return Value

None.

Exceptions

None.

Example

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

9.5 OrdHttpUploadFile Reference Information

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

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 Section 9.4 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.

This class extends java.lang.Object.


getContentLength( )

Format

public int getContentLength( )

Description

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

Parameters

None.

Return Value

This method returns the length of the uploaded file.

Exceptions

None.

Example

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 non-existent");
}
...
photo.release( );


getInputStream( )

Format

public java.io.InputStream getInputStream( )

Description

Returns an InputStream object that can be used to access the contents of the uploaded file directly. Applications should close the stream with the close( ) method when finished.

Parameters

None.

Return Value

This method returns an InputStream object.

Exceptions

java.io.IOException - if an error occurs opening the temporary file

java.lang.IllegalStateException - if the uploaded file is no longer available because it has been released

Example

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 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 media file as a String.

Exceptions

None.

Example

See getContentLength( ) for an example of this method.


getOriginalFileName( )

Format

public javalang.String getOriginalFileName( )

Description

Returns the original file name provided by the client. If no file name is provided, an empty String is returned.

Parameters

None.

Return Value

This method returns the file name, as a String.

Exceptions

None.

Example

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 no file name is provided, an empty String is returned.

Parameters

None.

Return Value

This method returns the simple file name as a String.

Exceptions

None.

Example

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 audio)

Description

Loads the media file into an OrdAudio object and sets the properties based on the audio contents. Assuming the application has already fetched an initialized OrdAudio object from the database, this method loads the contents of the audio file into the object and calls the OrdAudio.setProperties( ) method to set the audio properties. The application must then update the OrdAudio object in the database.

If the call to the setProperties( ) method fails, this method sets the following properties automatically:

This method does not use any existing format plug-in context information and does not set any comments while setting the properties.

Parameters

audio

An OrdAudio object into which the uploaded audio file will be loaded.

Return Value

None.

Exceptions

java.io.IOException - if an error occurs opening the temporary file

java.sql.SQLException - if an unrecognized error occurs while storing the media data

java.lang.IllegalStateException - 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 audio, byte[ ][ ] ctx, boolean setComments)

Description

Loads the media file into an OrdAudio object and sets the properties using an application-supplied format plug-in context. Assuming the application has already fetched an initialized OrdAudio object from the database, this method loads the contents of the audio file into the object and calls the OrdAudio.setProperties( ) method to set the audio properties. The application must then update the OrdAudio object in the database.

If the call to the setProperties( ) method fails, this method sets the following properties automatically:

The application provides the format plug-in context information and determines whether or not to set the comments in the OrdAudio object.

Parameters

audio

An OrdAudio object into which the uploaded audio file 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 - if an error occurs opening the temporary file

java.sql.SQLException - if an unrecognized error occurs while storing the media data

java.lang.IllegalStateException - 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");
}

byte[ ] ctx[ ] = new byte[4000][1];
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

The BLOB into which the data will be loaded.

Return Value

None.

Exceptions

java.io.IOException - if an error occurs opening the temporary file

java.sql.SQLException - if an unrecognized error occurs while storing the media data

java.lang.IllegalStateException - 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("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 doc)

Description

Loads the media file into an OrdDoc object and sets the properties based on the contents of the file. Assuming the application has already fetched an initialized OrdDoc object from the database, this method loads the contents of the file into the object and calls the OrdDoc.setProperties( ) method to set the properties. The application must then update the OrdDoc object in the database.

If the call to the setProperties( ) method fails, this method sets the following properties automatically:

This method does not use any existing format plug-in context information and does not set any comments while setting the properties.

Parameters

doc

An OrdDoc object into which the uploaded data will be loaded.

Return Value

None.

Exceptions

java.io.IOException - if an error occurs opening the temporary file

java.sql.SQLException - if an unrecognized error occurs while storing the media data

java.lang.IllegalStateException - 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("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 doc = (OrdDoc)rset.getCustomDatum(1, OrdDoc.getFactory( ));
uploadFile.loadDoc(doc);
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 doc, byte[ ][ ] ctx, boolean setComments)

Description

Loads the media file into an OrdDoc object and sets the properties using an application-supplied format plug-in context. Assuming the application has already fetched an initialized OrdDoc object from the database, this method loads the contents of the file into the object and calls the OrdDoc.setProperties( ) method to set the properties. The application must then update the OrdDoc object in the database.

If the call to the setProperties( ) method fails, this method sets the following properties automatically:

The application provides the format plug-in context information and determines whether or not to set the comments in the OrdDoc object.

Parameters

doc

An OrdDoc object into which the uploaded file 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 - if an error occurs opening the temporary file

java.sql.SQLException - if an unrecognized error occurs while storing the data

java.lang.IllegalStateException - 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("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[4000][1];
OrdDoc doc = (OrdDoc)rset.getCustomDatum(1, OrdDoc.getFactory( ));
uploadFile.loadDoc(doc, 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 image)

Description

Loads the media file into an OrdImage object and sets the properties based on the image contents. Assuming the application has already fetched an initialized OrdImage object from the database, this method loads the contents of the image file into the object and calls the OrdImage.setProperties( ) method to set the image properties. The application must then update the OrdImage object in the database.

If the call to the setProperties( ) method fails, this method sets the following properties automatically:

Parameters

image

An OrdImage object into which the uploaded image file will be loaded.

Return Value

None.

Exceptions

java.io.IOException - if an error occurs opening the temporary file

java.sql.SQLException - if an unrecognized error occurs while storing the media data

java.lang.IllegalStateException - 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("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 image, String cmd)

Description

Loads the media file into an OrdImage object and sets the properties based on the contents of the given String. Assuming the application has already fetched an initialized OrdImage object from the database, this method loads the contents of the image file into the object and calls the OrdImage.setProperties( ) method to set the image properties. The application must then update the OrdImage object in the database.

Parameters

image

An OrdImage object into which the uploaded image file will be loaded.

cmd

A String that specifies the properties to be set.

Return Value

None.

Exceptions

java.io.IOException - if an error occurs opening the temporary file

java.sql.SQLException - if an unrecognized error occurs while storing the media data

java.lang.IllegalStateException - 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("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 video)

Description

Loads the media file into an OrdVideo object and sets the properties based on the video contents. Assuming the application has already fetched an initialized OrdVideo object from the database, this method loads the contents of the video file into the object and calls the OrdVideo.setProperties( ) method to set the video properties. The application must then update the OrdVideo object in the database.

If the call to the setProperties( ) method fails, this method sets the following properties automatically:

This method does not use any existing format plug-in context information and does not set any comments while setting the properties.

Parameters

video

An OrdVideo object into which the uploaded video file will be loaded.

Return Value

None.

Exceptions

java.io.IOException - if an error occurs opening the temporary file

java.sql.SQLException - if an unrecognized error occurs while storing the media data

java.lang.IllegalStateException - 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("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 video = (OrdVideo)rset.getCustomDatum(1, OrdVideo.getFactory( ));
uploadFile.loadVideo(video);
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 video, byte[ ][ ] ctx, boolean setComments)

Description

Loads the media file into an OrdVideo object and sets the properties using an application-supplied format plug-in context. Assuming the application has already fetched an initialized OrdVideo object from the database, this method loads the contents of the video file into the object and calls the OrdVideo.setProperties( ) method to set the video properties. The application must then update the database OrdVideo object.

If the call to the setProperties( ) method fails, this method sets the following properties automatically:

The application provides the format plug-in context information and determines whether or not to set the comments in the OrdVideo object.

Parameters

video

An OrdVideo object into which the uploaded video file 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 - if an error occurs opening the temporary file

java.sql.SQLException - if an unrecognized error occurs while storing the media data

java.lang.IllegalStateException - 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("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[4000][1];
OrdVideo video = (OrdVideo)rset.getCustomDatum(1, OrdVideo.getFactory( ));
uploadFile.loadVideo(video, 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.

Example

See getContentLength( ) for an example of this method.


Go to previous page Go to next page
Oracle
Copyright © 1996-2001, 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