Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Get file in a gwt
Hi all! Sorry but I have some dudes.
I want fill a ListBox (gwt) with a file txt. But some issues happen. I am doing a RequestBuilder in the widget
Request request = builder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
displayError("Couldn't retrieve txt");
}
public void onResponseReceived(Request request,
Response response) {
if (200 == response.getStatusCode()) {
getFile(response.getText());
} else {
LOGGER.info("404!!!"); }
}
});
} catch (RequestException e) {
displayError("Couldn't retrieve txt");
}
and in a servlet the next:
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String rootPath = "";
rootPath = System.getProperty("catalina.home");
File file = new File(rootPath+ File.separator +"file.txt");
if (!file.exists()) {
throw new ServletException("File doesn't exists on server: " + context);
}
InputStream fis = new FileInputStream(file);
String mimeType = ctx.getMimeType(file.getAbsolutePath());
resp.setContentType(mimeType != null ? mimeType
: "application/octet-stream");
resp.setContentLength((int) file.length());
resp.setHeader("Content-Disposition", "attachment; filename=\""
+ "one.txt" + "\"");
ServletOutputStream os = resp.getOutputStream();
byte[] bufferData = new byte[1024];
int read = 0;
while ((read = fis.read(bufferData)) != -1) {
os.write(bufferData, 0, read);
}
os.flush();
os.close();
fis.close();
System.out.println("File downloaded at client successfully");
}
But doesn't works. Never enters in the doGet. And I test the widget (without vaadin implementations, only with the google toolkit) and works. I don't know if I have to send a Vaddin Request in the doGet or something like that.
Thank you so much!