Thanks lukehashj,
I started out trying to do this with RPC, but had no luck so now I
tried this HTTPRequest method. I am begining to think that neither way
is possible because they are both making asynchronous calls. Maybe I
need to figure out how to make a normal hyperlink call my servlet as
in a normal web app?? not sure how to do that in GWT so researching.
thanks
Sam




On Mar 24, 1:40 pm, lukehashj <[email protected]> wrote:
> This looks like an operation that should use an RPC.
>
> This may help 
> you:http://roberthanson.blogspot.com/2006/06/trivial-gwt-example.html
>
> On Mar 24, 1:06 pm, vroom_vroom <[email protected]> wrote:
>
>
>
> > Hello, I know this topic has been discussed in a few threads. I have
> > attempted to ask my questions in those but for some reason they are
> > not posting, so I had to create this new one. I read documentation and
> > other posts but still confused on how to do this. File download is
> > very simple in normal web app, but having trouble in GWT. Can someone
> > please help me with what I have written here?
>
> > This is code for client side :
> > [CODE]
> >   private void exportToExcel() {
> >           final int STATUS_CODE_OK = 200;
> >           final String url = "/exportExcel";
> >           RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
> > url);
>
> >             try {
> >               Request response = builder.sendRequest(null, new 
> > RequestCallback
> > () {
> >                 public void onError(Request request, Throwable exception) {
> >                   // TODO:
> >                 }
>
> >                 public void onResponseReceived(Request request, Response
> > response) {
> >                   // TODO:
> >                 }
>
> >               });
> >             } catch (RequestException e) {
> >               // TODO:
> >             }
> >   }
> > [/CODE]
>
> > This is in the ***.gwt.xml file:
> > [CODE]
> > <inherits name="com.google.gwt.http.HTTP" />
> > <servlet path="/exportExcel"
> > class="com.myweb.server.ExportExcelServlet" />
> > [/CODE]
>
> > This is my servlet:
> > [CODE]
> > package com.myweb.server;
>
> > import java.io.ByteArrayInputStream; ...
>
> > public class ExportExcelServlet extends HttpServlet {
>
> >    public void doGet(HttpServletRequest request,
> >             HttpServletResponse response)
> >             throws ServletException, IOException {
>
> >             response.setContentType("application/download");
> >             response.setHeader("Content-
> > Disposition","attachment;filename=temp.csv");
>
> >             try {
> >                         StringBuffer sb = generateCsvFileBuffer();
> >                         InputStream in = new 
> > ByteArrayInputStream(sb.toString().getBytes
> > ("UTF-8"));
> >                         ServletOutputStream out = 
> > response.getOutputStream();
>
> >                         byte[] outputByte = new byte[4096];
> >                         //copy binary contect to output stream
> >                         while(in.read(outputByte, 0, 4096) != -1)
> >                         {
> >                                 out.write(outputByte, 0, 4096);
> >                         }
> >                         in.close();
> >                         out.flush();
> >                         out.close();
> >                 } catch (Exception e) {
> >                         // TODO Auto-generated catch block
> >                         e.printStackTrace();
> >                 }
>
> >         }
>
> >         public void doPost(HttpServletRequest request,
> >             HttpServletResponse response)
> >             throws ServletException, IOException {
> >                 doGet(request,response);
> >         }
>
> >         private static StringBuffer generateCsvFileBuffer()
> >         {
> >                 StringBuffer writer = new StringBuffer();
>
> >                         writer.append("DisplayName");
> >                         writer.append(',');
> >                         writer.append("Age");
> >                         writer.append('\n');
>
> >                 writer.append("your name");
> >                         writer.append(',');
> >                         writer.append("30");
> >                         writer.append('\n');
>
> >                         return writer;
> >         }}
>
> > [/CODE]
>
> > At first I was having no errors generated but in the browser no
> > download dialog would pop up, and nothing happened.
> > I changed something...not sure what now, and getting runtime errors.
> > [ERROR] Unable to find 'exportExcel.gwt.xml' on your classpath; could
> > be a typo, or maybe you forgot to include a classpath entry for
> > source?
>
> > My entire app is written in GWT, so I dont have a web.xml file
>
> > I am very stuck any help would be extreemly appreciated
> > Thanks!- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to