file
in an HTML form, or an empty Enumeration if there are no input fields of type file
.file
in an HTML form.null
if the parameter does not exist.null
if the parameter does not exist.null
if the parameter does not exist.null
if the parameter does not exist.This class inherits the DEFAULT_BUFFER_SIZE field from the OrdHttpResponseHandler class.
if ( true ) { ... return; }
construct can 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.All the send methods in this class all call the JspWriter clear method to clear the page's output buffer prior to delivering the media. 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 the 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 by 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;
}
%>
In order to run Oracle Multimedia methods for servlets and JSP, you will need to import classes from the oracle.ord.im package into your Java file.
You may also need to import classes from the following Java packages:
java.sql.
java.io.
javax.servlet.
javax.servlet.http.
oracle.jdbc.
oracle.sql.
An Oracle Multimedia Java object, such as an OrdImage object, is not dependent on the JDBC statement or result set from which it was obtained. However, an Oracle Multimedia 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 Oracle Multimedia 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: public static final int DEFAULT_BUFFER_SIZE
.
The OrdHttpResponseHandler class uses a default buffer size of 32768 to retrieve LOB data from the database and deliver it to the client. You can override this value with the setBufferSize method.
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.getORAData( 1, OrdImage.getORADataFactory() );
OrdHttpResponseHandler handler =
new OrdHttpResponseHandler( request, response );
handler.sendImage(media);
}
else
{
response.setStatus( response.SC_NOT_FOUND );
}
rset.close();
stmt.close();
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 sendDoc
method will send the appropriate Content-Type header, allowing the browser to display the page correctly.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.getORAData( 1, OrdDoc.getORADataFactory() );
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();
In order to run Oracle Multimedia methods for servlets and JSP, you will need to import classes from the oracle.ord.im package into your Java file.
You may also need to import classes from the following Java packages:
java.sql.
java.io.
javax.servlet.
javax.servlet.http.
oracle.jdbc.
oracle.sql.
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 Oracle Multimedia 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 OrdHttpUploadFile.getOriginalFileName()
method will return the file name whose length is zero. However, if a user enters either an invalid file name or the name of an empty (zero-length) file, the getOriginalFileName method will return the file name whose length is not zero, and the OrdHttpUploadFile.getContentLength()
method will return the content length of the file as zero.
In order to run Oracle Multimedia methods for servlets and JSP, you will need to import classes from the oracle.ord.im package into your Java file.
You may also need to import classes from the following Java packages:
java.sql.
java.io.
javax.servlet.
javax.servlet.http.
oracle.jdbc.
oracle.sql.
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 OrdHttpUploadFormData.getFileParameter(java.lang.String)
, OrdHttpUploadFormData.getFileParameterValues(java.lang.String)
and OrdHttpUploadFormData.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 OrdHttpUploadFile objects, see the OrdHttpUploadFile
class.
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.getORAData( 1, OrdImage.getORADataFactory());
//
// 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.setORAData( 1, media );
stmt.setString( 2 id );
stmt.execute();
stmt.close();
//
// Commit the changes.
//
conn.commit();
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)
.file
in an HTML form produces a corresponding parameter of type OrdHttpUploadFile
, 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 the 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 for more information.
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=Shift_JIS ">
In order to run interMedia methods for servlets and JSP, you will need to import classes from the oracle.ord.im package into your Java file.
You may also need to import classes from the following Java packages:
java.sql.
java.io.
javax.servlet.
javax.servlet.http.
oracle.jdbc.
oracle.sql.
The OrdMultipartFilter class implements the javax.servlet.Filter interface in servlet 2.3. For any servlet container that supports servlet 2.3, this filter combined with the OrdMultipartWrapper object, provides transparent access to the parameters and files in the servlet request with multipart/form-data encoding.
In order to use the OrdMultipartFilter class, you will need to specify the following in the web.xml file:
<filter>
<filter-name>OrdMultipartFilter</filter-name>
<filter-class>oracle.ord.im.OrdMultipartFilter</filter-class>
<!-- optional configuration parameters
<init-param>
<param-name>tempDir</param-name>
<param-value>/tmp</param-value>
<param-name>maxMemory</param-name>
<param-value>5000</param-value>
</init-param>
-->
</filter>
<filter-mapping>
<filter-name>OrdMultipartFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
And you will need to specify the following in the JSP file:
//
// Get the description, location, and photograph.
//
String id = request.getParameter( "id" );
String description = request.getParameter( "description" );
String location = request.getParameter( "location" );
OrdHttpUploadFile photo = request.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.getORAData( 1, OrdImage.getORADataFactory());
//
// 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.setORAData( 1, media );
stmt.setString( 2 id );
stmt.execute();
stmt.close();
//
// Commit the changes.
//
conn.commit();
In order to run Oracle Multimedia methods for servlets and JSP, you will need to import classes from the oracle.ord.im package into your Java file.
You may also need to import classes from the following Java packages:
java.sql.
java.io.
javax.servlet.
javax.servlet.http.
oracle.jdbc.
oracle.sql.
In order to run Oracle Multimedia methods for servlets and JSP, you will need to import classes from the oracle.ord.im package into your Java file.
You may also need to import classes from the following Java packages:
java.sql.
java.io.
javax.servlet.
javax.servlet.http.
oracle.jdbc.
oracle.sql.