You really need to distinguish between java code on the client side of GWT and Java code on the server side.
Client-side in your Java GWT code
String url = GWT.getModuleBaseURL() + "downloadService?fileInfo1=" + fileInfo1; Window.open( url, "_blank", "status=0,toolbar=0,menubar=0,location=0");
On the server side, in non-gwt Java code -
In web.xml
<servlet> <servlet-name>downloadService</servlet-name> <servlet-class>AAA.BBB.CCC.DownloadServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>downloadService</servlet-name> <url-pattern>/<gwtmodulename>/downloadService</url-pattern> </servlet-mapping>
In servlet server package code
public class DownloadServlet extends HttpServlet{ protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException { String fileName = req.getParameter( "fileInfo1" ); int BUFFER = 1024 * 100; resp.setContentType( "application/octet-stream" ); resp.setHeader( "Content-Disposition:", "attachment;filename=" + "\"" + fileName + "\"" ); ServletOutputStream outputStream = resp.getOutputStream(); resp.setContentLength( Long.valueOf( getfile(fileName).length() ).intValue() ); resp.setBufferSize( BUFFER );
Make sure you click the contents of your file to **outputStream** .
SSR
source share