Source from server file to client.

import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Locale;

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 ReturnFile extends HttpServlet {

    private static final long serialVersionUID = -5297473193366880189L;

    public void doPost(HttpServletRequest requisicao, HttpServletResponse 
resposta)
            throws ServletException, IOException {
        this.processeRelatorio(requisicao, resposta);
    }

    protected void processeRelatorio(HttpServletRequest requisicao, 
HttpServletResponse resposta)
            throws IOException {
        PrintWriter out = null;
        ServletOutputStream outstream = null;
        try {
            // name report
            String nameFile = requisicao.getParameter("r000");
            FileInputStream entrada = new FileInputStream(nameFile);
            byte[] bytesFile = new byte[entrada.available()];
            entrada.read(bytesFile, 0, entrada.available());
            entrada.close();
            entrada = null;
            outstream = resposta.getOutputStream();
            resposta.setLocale(new Locale("pt,BR"));
            // type file.
            resposta.setContentType("application/pdf");
            resposta.setContentLength(bytesFile.length);
            resposta.setHeader("Content-disposition", "inline; 
filename=\"Report.pdf\"");
            outstream.write(bytesFile);
            bytesFile = null;
        } catch (IOException ioe) {
            out = resposta.getWriter();
            out.println(ioe.getLocalizedMessage());
            out.println(ioe.getCause());
        } finally {
            if (out != null) {
                out.flush();
                out.close();
            }
            if (outstream != null) {
                outstream.flush();
                outstream.close();
            }
        }
    }
}

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Reply via email to