Thank you. Here is the code I have:
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
ServletOutputStream out = response.getOutputStream ();
//---------------------------------------------------------------
// Set the output data's mime type
//---------------------------------------------------------------
response.setContentType( "application/pdf" ); // MIME type for pdf
doc //---------------------------------------------------------------
// create an input stream from fileURL
//---------------------------------------------------------------
String fileURL = "C:/jboss-4.0.4.GA/server/default/bill.pdf";
//------------------------------------------------------------
// Content-disposition header - don't open in browser and
// set the "Save As..." filename.
// *There is reportedly a bug in IE4.0 which ignores this...
//------------------------------------------------------------
response.setHeader("Content-Disposition", "attachment; filename=\"bill.pdf\"");
//-----------------------------------------------------------------
// PROXY_HOST and PROXY_PORT should be your proxy host and port
// that will let you go through the firewall without authentication.
// Otherwise set the system properties and use URLConnection.getInputStream().
//-----------------------------------------------------------------
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
URL url = new URL( "http", CWAAppConstants.PROXY_HOST,
Integer.parseInt(CWAAppConstants.PROXY_PORT), fileURL );
// Use Buffered Stream for reading/writing.
bis = new BufferedInputStream(url.openStream());
bos = new BufferedOutputStream(out);
byte[] buff = new byte[2048];
int bytesRead;
// Simple read/write loop.
while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
} catch(final MalformedURLException e) {
System.out.println ( "MalformedURLException." );
throw e;
} catch(final IOException e) {
System.out.println ( "IOException." );
throw e;
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
}
}
I am just not sure how to reference the servlet. Does it replace the action. Do I need to add an entry to the web.xml? I am not sure how to use it. I think if I was doing it new it would be easier but I am changing existing code and the
jsp calls an action.