You're setting objects as "session attributes", like a
Map of key-value pairs tied to the HTTP session.

-Matt

--- "Kenny G. Dubuisson, Jr."
<[EMAIL PROTECTED]> wrote:
> Bruno:
> 
> In the sample code you gave me, I don't understand
> what a couple of lines
> are doing.  The first one is:
>       MyPdfGenerator generator = (MyPdfGenerator)
> session.getAttribute("PDF");
> I understand that it's creating a new generator
> object but I don't know what
> the getAttibute is for (the other line I don't get
> is the call to
> setAttribute).  I've tried looking up the methods in
> the javax.servlet
> package but I can't seem to find the JavaDocs on
> that package.  If you
> wouldn't mind explaining the use of the attibute I
> would very much
> appreciate it.
> Thanks,
> Kenny
> 
> ----- Original Message -----
> From: "Kenny G. Dubuisson, Jr."
> <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, June 25, 2003 11:09 AM
> Subject: [iText-questions] Example of HTML "please
> wait" screen before PDF
> generation
> 
> 
> > Hello all.  I've been working on the capability of
> a "please wait" screen
> > that will display while my PDF is being generated.
>  I got some code from
> > Bruno and I've been trying to make it work to no
> avail.  What the code is
> > supposed to do is write to the output stream in
> HTML format the "please
> > wait" screen and refresh every 3 seconds.  If when
> it refreshes the
> document
> > is done, change the output stream to PDF and send
> the document.  I have it
> > to the point that it seems to switch to PDF but
> never displays the
> document
> > (which at this point is just a page with the word
> "test" on it).
> >
> > The code separated into two files: MyPdfGenerator
> and PleaseWait Servlet.
> > I've included the two pieces of code below.  Any
> ideas/comments would be
> > very much appreciated.  Once I get this working
> I'll post to the list for
> > future reference.  Thanks,
> > Kenny
> >
> > // MyPdfGeneration.java
> > import java.io.*;
> > import com.lowagie.text.*;
> > import com.lowagie.text.pdf.*;
> >
> > public class MyPdfGenerator implements Runnable
> > {
> >    public static final int NOT_STARTED = 0;
> >    public static final int BUSY = 1;
> >    public static final int FINISHED = 2;
> >    public static final int ABORTED = 3;
> >
> >    private int status = NOT_STARTED;
> >    private int counter = 0;
> >    private static final int TOTAL = 1000;
> >    private ByteArrayOutputStream baos = new
> ByteArrayOutputStream();
> >
> >    public void run()
> >    {
> >       try
> >       {
> >          status = BUSY;
> >          Document document = new
> Document(PageSize.LETTER, 0, 0, 0, 0);
> >          PdfWriter writer =
> PdfWriter.getInstance(document, baos);
> >          document.open();
> >          PdfContentByte cb =
> writer.getDirectContent();
> >
> >          document.add(new Paragraph("test"));
> >
> >          document.close();
> >          status = FINISHED;
> >       }
> >       catch (DocumentException de)
> >       {
> >          status = ABORTED;
> >       }
> >    }
> >
> >    public boolean isBusy()
> >    {
> >       return status == BUSY;
> >    }
> >
> >    public boolean isFinished()
> >    {
> >       return status == FINISHED;
> >    }
> >
> >    public boolean isAborted()
> >    {
> >       return status == ABORTED;
> >    }
> >
> >    public int getStatus()
> >    {
> >       return status;
> >    }
> >
> >    public int size()
> >    {
> >       return baos.size();
> >    }
> >
> >    public void writePdf(OutputStream out) throws
> IOException
> >    {
> >       baos.writeTo(out);
> >       out.flush();
> >       baos.close();
> >    }
> > }
> >
> > // PleaseWaitServlet.java
> > import java.io.*;
> > import javax.servlet.*;
> > import javax.servlet.http.*;
> >
> > public class PleaseWaitServlet extends HttpServlet
> > {
> >    protected void service(HttpServletRequest
> request,
> >       HttpServletResponse response) throws
> ServletException, IOException
> >    {
> >       HttpSession session =
> request.getSession(true);
> >       MyPdfGenerator generator = (MyPdfGenerator)
> > session.getAttribute("PDF");
> >       if (generator == null)
> >       {
> >          response.setHeader("Refresh", "3");
> >          generator = new MyPdfGenerator();
> >          Thread t = new Thread(generator);
> >          t.start();
> >          session.setAttribute("PDF", generator);
> >          doHtmlOutput(response, "document
> generation was initialized..." +
> >             "please wait");
> >          return;
> >       }
> >       if (generator.isBusy())
> >       {
> >          response.setHeader("Refresh", "3");
> >          doHtmlOutput(response, "document
> generation is busy...");
> >          return;
> >       }
> >       if (generator.isFinished())
> >       {
> >          doPdfOutput(response, generator);
> >          session.removeAttribute("PDF");
> >          return;
> >       }
> >       if (generator.isAborted())
> >       {
> >          doHtmlOutput(response, "document
> generation was aborted");
> >          session.removeAttribute("PDF");
> >          return;
> >       }
> >    }
> >
> >    protected void doHtmlOutput(HttpServletResponse
> response, String
> message)
> >       throws IOException
> >    {
> >       response.setContentType("Text/html");
> >       PrintWriter out = response.getWriter();
> >       out.println("<html><body>");
> >       out.println(message);
> >       out.println("</body></html>");
> >       out.flush();
> >       out.close();
> >    }
> >
> >    protected void doPdfOutput(HttpServletResponse
> response, MyPdfGenerator
> 
=== message truncated ===


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com


-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner.
Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to