File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Reading Excel file from Client side using servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Reading Excel file from Client side using servlet" Watch "Reading Excel file from Client side using servlet" New topic

Reading Excel file from Client side using servlet

Radheshyam Yadav

Joined: Dec 31, 2010
Posts: 1
When I run this code from client or another computer, It gives " 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.*;

@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

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

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!!

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
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!
It is sorta covered in the JavaRanch Style Guide.
subject: Reading Excel file from Client side using servlet
jQuery in Action, 3rd edition