// I know I'm not supposed to post source code here, but I thought this may
be useful for some.
// BTW I got most of the line below from an example which was posted here a
while ago.
// Sorry.. I forgot who posted it. But many thanks to the guy/girl who post
it in the first place

// Here, I put the HTML output into a StringBuffer and store it in the
session object
// under the name "PrintSummary". Then in the method below, I retrieved the
session
// StringBuffer from the session object to be saved into a file by the
browser


 public void print_to_file_method(HttpServletRequest request,
HttpServletResponse response)
 throws IOException, ServletException
 {
  HttpSession session = request.getSession(true);
  StringBuffer page = (StringBuffer)session.getValue("PrintSummary");

  if(request.getHeader("user-agent").indexOf("MSIE")!= -1)
  {
  response.setContentType("application/x-my-type");

response.setHeader("Content-Disposition","inline;filename=payroll_summary");
  }
  else
  {
  response.setContentType("application/octet-stream");

response.setHeader("Content-Disposition","inline;filename=payroll_summary.ht
m");
  }

  PrintWriter out;
  out = response.getWriter();

  try
  {
   out.println(page.toString());
  }
  catch (Exception ex)
  {
   out.println(ex.getMessage());
   ex.printStackTrace(out);
  }

  out.flush();
  out.close();
 }

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to