This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I read a excel file from the response

 
renisha suny
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sending an excel file from backend as a servlet reponse.

Example:

response.set("Content-Type", "application/vnd.ms-excel");
response.set("Content-Disposition", "attachment; filename=sampleName.xls");

WritableWorkbook w = Workbook.createWorkbook(responseBody);
WritableSheet s = w.createSheet("Demo", 0);

s.addCell(new Label(0, 0, "Hello World"));
w.write();
w.close();
responseBody.flush();
responseBody.close();

Now, I need to read the excel file in the client side .
Can anyone please provide me withe sample code.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of client are we talking about - web browser, Java desktop app, something else?
 
renisha suny
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a GWT code on whose button click I invoke this servlet:

I have a servlet which connects to another server using HttpURLConnection

urlParameters = "operation=getData";
HttpURLConnection connection = HTTPUtils.getConnection(PropertyRemoteServlet.Host);
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(urlParameters);
wr.flush();
wr.close();

And in the backend server:

I am fetching some data and writing to an excel as:

public class HttpDataHandler implements HttpHandler {
Headers responseHeaders = exchange.getResponseHeaders();
exchange.sendResponseHeaders(200, 0);
OutputStream responseBody = exchange.getResponseBody();


exchange.getResponseHeaders().set("Content-Type", "application/vnd.ms-excel");
exchange.getResponseHeaders().set("Content-Disposition", "attachment; filename=sampleName.xls");

WritableWorkbook w = Workbook.createWorkbook(responseBody);
WritableSheet s = w.createSheet("Demo", 0);
s.addCell(new Label(0, 0, "Hello World"));
w.write();
w.close();
responseBody.flush();
responseBody.close();

}


Now, I need to display this excel in the browser.
I am not able to get the reponse in the abpve mentioned servlet from the backend server.

Please can figure out the issue with the above code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic