Take a look at the doGet method ;) I pointed out to the wrong UI class though, this one show a file browser and the user downloads any of the files by clicking on it: http://code.google.com/p/hellagwt/source/browse/trunk/hellagwt/src/main/java/fr/salvadordiaz/gwt/hellagwt/client/views/DownloadsPanel.java
Hope that helps, Salvador On 15 mai, 11:59, Scientist <[email protected]> wrote: > That's a piece of code to upload a file from client to server if I > understand this correctly, in my case it needs to be the other way > around. The system writes an XLS-file to the server, and the user > needs to download that file to his laptop. > > Thanks anyway! > > On May 15, 11:52 am, Salvador Diaz <[email protected]> wrote: > > > Hi, > > > I answered this yesterday in this > > post:http://groups.google.com/group/Google-Web-Toolkit/msg/9456d6f4a8ba0574 > > > So here's the servlet code I > > use:http://code.google.com/p/hellagwt/source/browse/trunk/hellagwt/src/ma... > > And here's the UI > > code:http://code.google.com/p/hellagwt/source/browse/trunk/hellagwt/src/ma... > > > You could also check out the whole project and build-test it with > > maven. > > > Hope that helps, > > > Salvador > > > On 15 mai, 11:37, Scientist <[email protected]> wrote: > > > > Hi all, > > > > I'm working on a GWT-project, and I got stuck in the part where I need > > > to send a file on the server-side to the browser, so a user can > > > download the file. I've done some reading, and found out the best way > > > to do this is to write a servlet which gets called from the project. > > > I've found a piece of code for the servlet: > > > > [quote] > > > import java.io.DataInputStream; > > > import java.io.File; > > > import java.io.FileInputStream; > > > import java.io.IOException; > > > import javax.servlet.ServletContext; > > > import javax.servlet.ServletException; > > > import javax.servlet.ServletOutputStream; > > > import javax.servlet.http.HttpServlet; > > > import javax.servlet.http.HttpServletRequest; > > > import javax.servlet.http.HttpServletResponse; > > > > public class DownloadServlet extends HttpServlet { > > > private static final long serialVersionUID = 1L; > > > > public DownloadServlet() { > > > super(); > > > } > > > > protected void doGet(HttpServletRequest request, > > > HttpServletResponse > > > response) throws ServletException, IOException { > > > > } > > > > protected void doPost(HttpServletRequest request, > > > HttpServletResponse > > > response) throws ServletException, IOException { > > > } > > > > private void doDownload( HttpServletRequest req, > > > HttpServletResponse resp, String filename, String original_filename ) > > > throws IOException { > > > File f = new File(filename); > > > int length = 0; > > > ServletOutputStream op = resp.getOutputStream(); > > > ServletContext context = getServletConfig().getServletContext(); > > > String mimetype = context.getMimeType( filename ); > > > > resp.setContentType( (mimetype != null) ? mimetype : "application/ > > > octet-stream" ); > > > resp.setContentLength( (int)f.length() ); > > > resp.setHeader( "Content-Disposition", "attachment; filename=\"" + > > > original_filename + "\"" ); > > > > byte[] bbuf = new byte[0]; > > > 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(); > > > }} > > > > [/quote] > > > > Don't know if this is usefull code, it doesn't give any errors in > > > Eclipse so that's a good start. Now for the main question: how do I > > > integrate this servlet in my GWT-project? In other words: what kind of > > > code do I have to place under the button so the servlet gets > > > triggered? > > > > Trying to figure out for 3 days, so I hope someone knows the answer.- > > > 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 -~----------~----~----~----~------~----~------~--~---
