• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading Excel file from Client side using servlet

 
Radheshyam Yadav
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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);
}
}
}
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • 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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic