import java.io.ByteArrayOutputStream; import java.sql.Blob; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletOutputStream; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping;
public class BLOBServerAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm inForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
try {
String bTable = "the_table_the_blob_is_in"; String bField = "the_field_the_blob_is_in"; String bQuery = "where_clause_to_select_proper_record;
String sql = "select " + bField + "," + bField + "_ctype from " + bTable + " where " + bQuery;
Blob blob = null;
String contentType = null;
byte[] bytes = null;
ResultSet rs = doSelect(sql); // Insert database access here, just use the above constructed SQL string
while (rs.next()) {
contentType = rs.getString(bField + "_ctype");
blob = rs.getBlob(bField);
}
ServletOutputStream out = response.getOutputStream();
response.setContentType(contentType); if (blob != null) { bytes = blob.getBytes(1, (int)(blob.length())); ByteArrayOutputStream ba = new ByteArrayOutputStream(); ba.write(bytes, 0, bytes.length); ba.writeTo(out); } out.flush();
} catch (Exception e) {
e.printStackTrace();
}
return null;
} // End process()
}
Hope that helps, if you go this route.
Frank W. Zammetti Chief Software Architect Omnytex Technologies www.omnytex.com
From: "Jesse Alexander (KXT)" <[EMAIL PROTECTED]> Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]> To: Struts Users Mailing List <[EMAIL PROTECTED]> Subject: RE: struts and iText Date: Tue, 3 Aug 2004 10:49:08 +0200
Well,...
If you already have the PDF generated, why not directly write it to the response(and in this way to the browser)?
To fulfill your use case as described.
Your action generates the PDF and caches it somewhere. Then it will forward to the JSP-File containing the message and the link. This link either points to a Struts-Action or a plain servlet. This target-Servlet (or Action) retrieves the cached PDF and sends it to the browser.
Where to cache?
a) File-System
- you need a writable location and remember to install some cleaning mechanism
- the link presented could be just the reference to the cached file if that directory
readable by the webserver
b) user-session
- dangerous in a clustered environment (too much stuff to propagate around)
- memory usage (usually the recommendation is not to use more than 4K in session...)
- PDF only available to original user
- easy to program
c) separate cache
- adds another component to your app (DO NOT roll your own cache, there are quite a
number of tested cache-libraries)
- could make the PDF available also to other users (depends on the use-case and the
cache-library)
hope this helps Alexander
-----Original Message----- From: Otto, Frank [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 03, 2004 9:18 AM To: '[EMAIL PROTECTED]' Subject: struts and iText
Hi,
I have generated a pdf with iText. In my action class I want to write it in the response object.
The result should be a jsp-page with content "pdf generated successful" and a link to this pdf. The pdf should be shown in a new browser window too.
Has someone do this? How can I do this?
kind regards,
frank
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
_________________________________________________________________
Planning a family vacation? Check out the MSN Family Travel guide! http://dollar.msn.com
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]