• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading Excel file from Client side using servlet

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I run this code from client or another computer, It gives "java.io.FileNotFound Exception". And It says, "The system can not find the file specified".
Please provide me appropriate code to do this.


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jxl.*;
import jxl.read.biff.BiffException;
import java.io.*;

@WebServlet(name = "UploadFile", urlPatterns = {"/UploadFile"})
public class UploadFile extends HttpServlet {




public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
OutputStream out = null;
PrintWriter out1 = response.getWriter();
String filename = request.getParameter("file");
out1.println("Filename [" + filename + "]");
Workbook workbook = null;
try {
workbook = Workbook.getWorkbook(new File(filename));
} catch (BiffException e) {

// TODO Auto-generated catch block
e.printStackTrace();
}

Sheet[] sheet = workbook.getSheets();
int rows = sheet[0].getRows() + 1;

NextRow:
for (int row = 1; row < rows - 1; row++) {

//Cell colcell = sheet[0].getCell(1, rw);
String column = sheet[0].getCell(1, row).getContents().trim();
// this is all you had to add lol!!

out1.println(column);
}
}
}
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by "run this code from client or another computer"? It's a servlet, so it runs on the server.

While it's not clear what you mean by "this" in "to do this", if you're trying to access files on the client computer then that is impossible - imagine the security implications if it were!
 
"To do good, you actually have to do something." -- Yvon Chouinard
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic