GWT and Generated file download

947 views
Skip to first unread message

Appien

unread,
Dec 9, 2011, 7:05:19 AM12/9/11
to Google Web Toolkit
Hi folks,

At the moment I'm having troubles with starting a file download using
GWT. In my application we have a Form object which contains all data
which should be stored on a PDF file. Currently my applications works
like this to generate the file and start the download.

1. Do a RPC call to store a form object in the session
2. If succesfull, call servlet by a GET method
3. Get the form object out of the session, genereate the pdf and write
the Response object

However, this solutions fails due to the fact that during the calls 2
sessions gets created. The first one when I do an RPC call to store
the form in the session. When the RPC call is finished the session
gets destroyed. The second session is created when I do a call to the
servlet. The servlet cannot find the stored Form object as the session
in which the Form object is stored is already destroyed.

How can I handle the different created sessions on the server?

As GWT cannot handle file download using RPC, an alternative solution
would be to create a tempory file. In this solution I would create a
RPC call which creates a file with an unique filename. When this file
is created, I call the servlet to get the file. Is this a nice
solution for this problem or is there a more nifty solution?

Regards,

Eric Metcalf

unread,
Dec 9, 2011, 12:17:46 PM12/9/11
to Google Web Toolkit
Skip doing the RPC request. Create a file HttpServlet (don't forget
to add it to web.xml). Use the FormPanel (http://google-web-
toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/user/client/
ui/FormPanel.html) and set the Action to the file HttpServlet.

Now you can act like a normal servlet; Override do post, read params,
write file.

Jim Douglas

unread,
Dec 9, 2011, 2:23:07 PM12/9/11
to Google Web Toolkit

Tony Edgin

unread,
Dec 9, 2011, 11:34:21 AM12/9/11
to google-we...@googlegroups.com
In your proposed solution, you would need an external mechanism for
ensuring that the temporary file was removed in the following
exceptional case. An RPC creates the temporary file, but the client
never calls the servlet GET to retrieve the file. This could happen
if the user goes to a different web site in the middle of the request.

I have a similar problem. To solve my problem, I just directly send
the form data as parameters to the servlet GET and not use an RPC.
That way there's no risk of leaking temp files.

> --
> You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
> To post to this group, send email to google-we...@googlegroups.com.
> To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
>

--
Tony Edgin
Software Architecture and Design Leader
LBT Observatory
933 N. Cherry Ave., Tucson AZ 85721-0065
p:520-626-8951, c:520-419-8821, f:520-626-9333

Appien

unread,
Dec 12, 2011, 2:17:03 AM12/12/11
to Google Web Toolkit
Thanks so far. Unfortunately the application contains more than 8
forms with more than 60 fields. The mapping to object and to a file
mechanism is already built in the past. This would make the solution
to change the forms to use a FormPanel and setting all the parameters
a solution which requires a lot of work (which we don't have :( )

I see the problem Tony mentioned. Is there not another way to store
the object which contains all data temporary on the server? By
something like a special session which has a different expiration
time?

> > For more options, visit this group athttp://groups.google.com/group/google-web-toolkit?hl=en.

kim young ill

unread,
Dec 12, 2011, 2:55:26 AM12/12/11
to google-we...@googlegroups.com
depends how long u wanna keep the files. u can store files somewhere, put filepath in session, when session got destroyed ( put a listener in contextlistener), read out the paths and remove them.

hth
Reply all
Reply to author
Forward
0 new messages