File upload/Download Using GWT

2,009 views
Skip to first unread message

dasaradha

unread,
Dec 3, 2007, 10:51:57 PM12/3/07
to Google Web Toolkit
Please tell me which is the right mime type to use in file Download
gwt because i am using the following code

...
HttpServletResponse response = this.getThreadLocalResponse();
...
response.setContentType("application/ms-excel");
response.setHeader("Content-Disposition",
"inline; filename="+filename);

java.io.PrintWriter out = response.getWriter();
out.write("This is a test.");
out.flush();
out.close();

But got following exception came out just immediately after
"out.close",
com.google.gwt.user.client.rpc.InvocationException

Pls Give me good idea about this Problem

mP

unread,
Dec 4, 2007, 4:30:41 AM12/4/07
to Google Web Toolkit
Your file server servlet should not be aprt of a RPC ServiceServlet.
Just write a plain old vanilla FileServer serlvet and youll be fine.

You cant download/upload files via ajax so it doenst make sense to try
and send or receive (a file from or too the user) a file via an rpc.

dasaradha

unread,
Dec 4, 2007, 9:49:48 PM12/4/07
to Google Web Toolkit
Thanks for giving quick reply i am new for GWT Actually i am trying
to upload and download Excel file using GWT
what is the process to download Excel file using GWT Pls give me
better solution.


On Dec 4, 6:30 pm, mP <miroslav.poko...@gmail.com> wrote:
> Yourfileserver servlet should not be aprt of a RPC ServiceServlet.
> Just write a plain old vanilla FileServer serlvet and youll be fine.
>
> You cantdownload/uploadfiles via ajax so it doenst make sense to try
> and send or receive (afilefrom or too the user) afilevia an rpc.
>
> On Dec 4, 2:51 pm, dasaradha <dasara...@gmail.com> wrote:
>
> > Please tell me which is the right mime type to use in fileDownload
> >gwtbecause i amusingthe following code

ck_rookie

unread,
Dec 20, 2007, 9:19:16 AM12/20/07
to Google Web Toolkit



File f = new File("xxx);

String filename = f.getName();

int length = 0;
ServletOutputStream op = resp.getOutputStream();
ServletContext context = getServletConfig().getServletContext();
resp.setContentType("application/octet-stream");
resp.setContentLength((int) f.length());
resp.setHeader("Content-Disposition", "attachment; filename*=
\"utf-8''" + filename + "");

byte[] bbuf = new byte[1024];
DataInputStream in = new DataInputStream(new FileInputStream(f));

while ((in != null) && ((length = in.read(bbuf)) != -1)) {
op.write(bbuf, 0, length);
}

in.close();
op.flush();
op.close();
Reply all
Reply to author
Forward
Message has been deleted
0 new messages