Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8130259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:38:51+00:00 2026-06-06T08:38:51+00:00

i am developing a .xls reader who take .xls file and read that,, and

  • 0

i am developing a .xls reader who take .xls file and read that,, and give the output as plain text
but i am facing some problem to get the file path into the servlet … i am using poi.jar to read the .xls file ..

.jsp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Upload Form</title>

    </head>


    <body bgcolor="lightblue">
 <table id='table1' align="center" >
                <tr>

                </tr></table><br/><br/><br/>  
            <br/>

            <table border="1" width="50%" bgcolor="#C2DFFF">
                <tr>
                    <td width="100%">
                        <form action="writeExcel" method="post" enctype="multipart/form-data">

                            <h2 align="center">Welcome</h2>
  <center>

      <input type="file" name="photo"/>
                                <input type="file" name="hem"/>
                                <br/><br/>
                                <input type="submit" value="Save"/>
                                &nbsp;
                                <input type="button" value="Logout" name="logout" onclick="goToURL();" />
                                <br/>
                                <br/>

                            </center>     
                        </form>
                    </td>
                </tr>
</table>

            <br/><br/>


    </body>
</html>

.java

import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class writeExcel extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        String fileName = request.getParameter("hem");



       Vector dataHolder = ReadCSV(fileName);
        printCellDataToConsole(dataHolder);
    }

   public static Vector ReadCSV(String fileName) {
        Vector cellVectorHolder = new Vector();

        try {
            FileInputStream myInput = new FileInputStream(fileName);

            POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);

            HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);

            HSSFSheet mySheet = myWorkBook.getSheetAt(0);

            Iterator rowIter = mySheet.rowIterator();

            while (rowIter.hasNext()) {
                HSSFRow myRow = (HSSFRow) rowIter.next();
                Iterator cellIter = myRow.cellIterator();
                Vector cellStoreVector = new Vector();
                while (cellIter.hasNext()) {
                    HSSFCell myCell = (HSSFCell) cellIter.next();
                    cellStoreVector.addElement(myCell);
                }
                cellVectorHolder.addElement(cellStoreVector);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return cellVectorHolder;
    }

    private static void printCellDataToConsole(Vector dataHolder) {

        for (int i = 0; i < dataHolder.size(); i++) {
            Vector cellStoreVector = (Vector) dataHolder.elementAt(i);
            for (int j = 0; j < cellStoreVector.size(); j++) {
                HSSFCell myCell = (HSSFCell) cellStoreVector.elementAt(j);
                String stringCellValue = myCell.toString();
                System.out.print(stringCellValue + "\t");
            }
            System.out.println();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:38:53+00:00Added an answer on June 6, 2026 at 8:38 am

    @AVD : Does fileName represent an absolute path of file/doc? If not then set/obtain real (absolute) path.

    @Nitin Sharma: thank you AVD.. when i am using finename=”C:\a.xls” is working fine But i am trying to take path from .jsp through file , it gives only file name not full path

    @AVD : You have to save the uploaded file under your web-app root (or subfolder) or use InputStream (Servlet 3.0 Part or Apache fileupload api) object of uploaded file instead of fileName.

    @Nitin Sharma : i don’t want to upload file … i just want to get full path of that file ..

    @AVD : There is nothing left to say! There is no choice. (Do not save the uploaded file instead use the stream of uploaded file).

    @Nitin Sharma: i used that but poi use File class object to read the file.. but Apache fileupload api use FileItem class object to read or get the path of the .xls file… and i am not able to typecast FileItem to File


    Take a look at POIFSFileSystem class, it takes InputStream parameter and you may obtain via FileItem.getInputStream() (Commons upload).

    POIFSFileSystem myFileSystem = new POIFSFileSystem(fileItem.getInputStream());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a Python script that uses xlrd to obtain data from xls
We need to update some cells of an Excel file (either xls or xlsx)
We need to update some cells of an Excel file (either xls or xlsx)
Developing with my first Mac and I noticed that my Rspec output isn't colorized
Developing a series of POCOs on my project, and just realized that some of
I am developing an application in which i have to get data from .xls
Developing a project of mine I realize I have a need for some level
I´m developing a software in C# that uses static functions from a C++ .dll
Developing rails has become lots of fun over the year that I've done it,
Developing search utility to search a file entire computer system, works fine on windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.