Read an excel file using JSP in MII 12.1

Hi,
I want to read an excel file using jsp page. I dont want to use the UDS or ODBC for connecting to excel.
I am trying to use org.apache.poi to read the excel file in jsp page.
While running, its showing a compilation error "package org.apache.poi.hssf.usermodel does not exist"
I have the jar files for it, where do we need to upload it so that jsp page works.
Thanks a lot
Regards,
Neha Maheshwari

The user doesn't want to save the excel file in server.
I want to upload file and save its contents in database.
I have the code to read and save excel data in database but not able to get the location to deploy the jar file.
In general, if we are creating a jsp page in MII workbench which is using some jar file.
Whats the location to upload this jar file so that the jsp page works correctly?

Similar Messages

  • I would like to upload a excel file using jsp

    Hi,
    I would like to upload the excel file using jsp in my netbeans ide. Please help.
    I don Know what is the error in this jsp file. It is not showing any thing and the file is also not getting uploaded.
    Please gothru the code below.
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
    <%@ page import="java.io.*" errorPage="err.jsp"%>
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="<html:rewrite page="/design.css" />" rel="stylesheet" type="text/css">
    <title>Upload Page</title>
    </head>
    <body onKeyDown="DisablingBackFunctionality()" onLoad="DisablingBackFunctionality()">
    <html:form action="download" >
    <div style="position:absolute; left:100;top:200;">Select an excel File :<input type="file" name="uploadfile"></div>
    <div style="position:absolute; left:190;top:250;"><input type="submit" name="Submit" value="Read"></div>
    <div style="position:absolute; left:336;top:250;"><input type="reset" name="Reset" value="Clear"></div>
    mainmenu
    </html:form>
    </body>
    </html>
    <%
    String contentType = request.getContentType();
    if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
    DataInputStream in = new DataInputStream(request.getInputStream());
    int formDataLength = request.getContentLength();
    byte dataBytes[] = new byte[formDataLength];
    int byteRead = 0;
    int totalBytesRead = 0;
    while (totalBytesRead < formDataLength) {
    byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
    totalBytesRead += byteRead;
    String file = new String(dataBytes);
    //out.println("<br> file :"+file);
    String saveFile = file.substring(file.indexOf("filename=\"") + 10);
    //out.println("<br> savefile :"+saveFile);
    saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
    //out.println("<br> now file1 :"+saveFile);
    saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1, saveFile.indexOf("\""));
    //out.println("<br> now file2 :"+saveFile);
    //out.print(dataBytes);
    String ext = "";
    if (saveFile.indexOf(".") != -1) {
    ext = saveFile.substring(saveFile.lastIndexOf("."));
    int lastIndex = contentType.lastIndexOf("=");
    //out.println("<br>lst index of"+lastIndex);
    String boundary = contentType.substring(lastIndex + 1, contentType.length());
    //out.println("<br> boundary"+boundary);
    //out.println("<br> file :"+file);
    int pos;
    pos = file.indexOf("filename=\"");
    //out.println("<br> now 0 :"+pos);
    pos = file.indexOf("\n", pos) + 1;
    //out.println("<br>now 1 :"+pos);
    pos = file.indexOf("\n", pos) + 1;
    //out.println("<br>now 2 :"+pos);
    pos = file.indexOf("\n", pos) + 1;
    //out.println("<br>now 3"+pos);
    int boundaryLocation = file.indexOf(boundary, pos) - 4;
    int startPos = ((file.substring(0, pos)).getBytes()).length;
    int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
    FileOutputStream fileOut = new FileOutputStream("D:\\" + saveFile);
    //FileOutputStream fileOut = new FileOutputStream(saveFile);
    //fileOut.write(dataBytes);
    fileOut.write(dataBytes, startPos, (endPos - startPos));
    fileOut.flush();
    fileOut.close();
    session.setAttribute("fil", saveFile);
    //out.println("File saved as " +saveFile);
    %>
    <script type="text/javascript" >
    function DisablingBackFunctionality()
    var URL;
    var i ;
    var QryStrValue;
    URL=window.location.href ;
    i=URL.indexOf("?");
    QryStrValue=URL.substring(i+1);
    if (QryStrValue!='X')
    window.location=URL + "?X";
    </script>
    Please let me know the result as soon as possible. Its my very urgent.
    Thanking Yu,
    Muthu Kumar.R

    No.
    Mylenium

  • Read a excel file using swings

    Does anyone know about reading an excel file using swings?
    Right now, I am using com.f1j.ss.*. But looking for more examples like reading and writing a excel file.
    Please suggest me with some good examples?

    1- Swing allows you to design a graphical user interface (to display data from a db or excel file for example)
    2- [Here |http://www.rgagnon.com/javadetails/java-0516.html] several ways to read/write excel.

  • Read&write Excel file using java

    Hi everybody,
    I have an assignment about methods that read and write an excel file using java (Eclipse SDK), so if anyone know about that please post the solution as soon as possible.
    Thanks
    Sendbad

    http://onesearch.sun.com/search/onesearch/index.jsp?qt=read+write+excel&subCat=siteforumid%3Ajava31&site=dev&dftab=siteforumid%3Ajava31&chooseCat=javaall&col=developer-forums

  • How to read the excel file using webdynpro abap?

    Hi,
    how to read and modify excel file using webdynpro abap?
    Regards,
    Pavani

    For reading excel file follow the steps :
    1. Use a File upload UI element and bind it with xstring.
    2. Now your excel will be uploaded and stored in Xstring.
    3. Convert Xstring to String data using FM 'HR_KR_XSTRING_TO_STRING'.
    4. Now split the string at new line so as to make an internal table .
      Ex . SPLIT l_string  AT cl_abap_char_utilities=>newline INTO TABLE it_table.
      here it_table is type table of string.
    5.now loop at the internal table and separate the content of this table separated by tab.
      Ex. SPLIT wa_table AT cl_abap_char_utilities=>horizontal_tab INTO TABLE it_new.
    it_new type string_table.
    6. For more info , refer this thread :
    Re: How to upload excel file in Webdynpro application using ABAP

  • Download Excel file using JSP

    Hi All,
    I am working on a JAVA/JSP application. JSP page passes the user inputs to JAVA page (using POST method) which queries to the database and generate an Excel file and returns the link for that file. I am displaying that link in JSP page ("Your file is successfully saved. Click here to download or view your file).
    Now what I want is when the user clicks on the link, open/save dialog will appear which give flexibility to the user to download or view the file in same JSP page. The problem is I don�t want to post again the data or dont want to open a child window. How to set the content type without posting it (I don�t know much about this). Is there any way to do this?
    Any help is highly appreciated. Thanx in advance
    Cheers
    Inderpal

    Hi
    Iam retreiving a file which is in image type in Ms SQl database, but while im retreiving the data from database using Servlet OutputStream the data is showing in binary format with all speciall symbols and text inside .Iamunable to find the solution for that,
    Pleas help me
    my code
              response.setContentType("application/msword");                    
                   OutputStream ros = response.getOutputStream();
              ros.flush();
                   ros.write(bt,0,bt.length);
    Thankz for ur help ,
    my id: [email protected]

  • Read an excel file using java code

    Hi,
    I want to create an excel file on the client machine based on the personal details entered on the web page. And I want to save the file on the client machine in the form of CSV. Then I want to read the contents of the spreadsheet using Java Code from the using servlets. Can I read the contents of the file directly from the client machine or do i need to save the file on the server and then read the contents of it. Please help me solve this.

    Hi,
    I want to create an excel file on the client machine
    based on the personal details entered on the web
    page. And I want to save the file on the client
    machine in the form of CSV. Then I want to read the
    contents of the spreadsheet using Java Code from the
    using servlets. Can I read the contents of the file
    directly from the client machine or do i need to save
    the file on the server and then read the contents of
    it. Please help me solve this.As stated I am rather certain that is impossible.
    Servers don't access the file systems of client machines.

  • Read an Excel file using POIFSFileSystem API

    hello,
    I'm working on J2EE web assignment. Following is my requirement
    1) User select local excel file and hit submit
    2) API takes that file read and create a new Excel file.
    I am wondering if I can somehow get inputsteam on form post and then pass it to POI api
    POI api syntax
    POIFSFileSystem fs = new POIFSFileSystem(java.io.InputStream);
    thanks,
    Amit

    there are plenty of tutorials and docs online
    this site is for technical help, general questions should be submitted to Google

  • Read / Write Excel file using package dbms_util and util_files

    hi,
    i am beginner to this so please elaborate the answer more concisely

    there's a ton of reading on this subject on google my friend.
    http://www.google.co.uk/search?hl=en&source=hp&biw=954&bih=517&q=plsql+read+write+excel&btnG=Google+Search&aq=f&aqi=&aql=&oq=plsql+read+write+excel
    and check the forum faq, there's a topic on excel in here:
    SQL and PL/SQL FAQ
    Edited by: smon on Mar 2, 2011 3:39 AM

  • Can't read special characters in an excel file using JDBC

    Hi! I 've a code to read an excel file using JDBC-ODBC bridge. I can read the values, but any special characters is readed wrong, just symbols. The special characters are of spanish language. This is my code:
                    Locale currentLocale;
              currentLocale = new Locale("es", "MX");
              Locale.setDefault(currentLocale);
                   Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
                   c = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=comisionesperfiles.xls");
                   stmnt = c.createStatement();
                   String query = "Select * from [Hoja1$]" ;
                   ResultSet rs = stmnt.executeQuery( query );
                   while( rs.next() ){
                        String valor = rs.getString(2) ;
                        if(valor != null && !"null".equalsIgnoreCase(valor)){
                             if(!comisiones.contains(valor)){
                                  System.out.println(valor);
                                  comisiones.add( valor );
                   rs.close();
                   stmnt.close();As you can see, I've tried to set the locale, but it didn't work.
    I'm using Excel 2003, Java Version 1.4.2_07 and Windows XP Professional (in latin american spanish).
    Hope someone can help me!

    FYI: Apache's POI can read/write Excel files in Java:
    http://jakarta.apache.org/poi/index.html

  • Getting an Error after reading a excel file

    hi
    I am reading a excel file using POI
    my code is
    package businessLogic;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
    import org.apache.poi.hssf.eventusermodel.HSSFListener;
    import org.apache.poi.hssf.eventusermodel.HSSFRequest;
    import org.apache.poi.hssf.record.BOFRecord;
    import org.apache.poi.hssf.record.BoundSheetRecord;
    import org.apache.poi.hssf.record.LabelSSTRecord;
    import org.apache.poi.hssf.record.NumberRecord;
    import org.apache.poi.hssf.record.Record;
    import org.apache.poi.hssf.record.RowRecord;
    import org.apache.poi.hssf.record.SSTRecord;
    import org.apache.poi.poifs.filesystem.POIFSFileSystem;
    * This example shows how to use the event API for reading a file.
    public class EventExample implements HSSFListener
    private SSTRecord sstrec;
    * This method listens for incoming records and handles them as required.
    * @param record The record that was found while reading.
    public void processRecord(Record record)
         try
    switch (record.getSid())
    // the BOFRecord can represent either the beginning of a sheet or the workbook
    case BOFRecord.sid:
    BOFRecord bof = (BOFRecord) record;
    if (bof.getType() == bof.TYPE_WORKBOOK)
    System.out.println("Encountered workbook");
    // assigned to the class level member
    } else if (bof.getType() == bof.TYPE_WORKSHEET)
    System.out.println("Encountered sheet reference");
    break;
    case BoundSheetRecord.sid:
    BoundSheetRecord bsr = (BoundSheetRecord) record;
    System.out.println("New sheet named: " + bsr.getSheetname());
    break;
    case RowRecord.sid:
    RowRecord rowrec = (RowRecord) record;
    System.out.println("Row found, first column at " + rowrec.getFirstCol() + " last column at " + rowrec.getLastCol());
    break;
    case NumberRecord.sid:
    NumberRecord numrec = (NumberRecord) record;
    System.out.println("Cell found with value " + numrec.getValue()+ " at row " + numrec.getRow() + " and column " + numrec.getColumn());
    break;
    // SSTRecords store a array of unique strings used in Excel.
    case SSTRecord.sid:
    sstrec = (SSTRecord) record;
    for (int k = 0; k < sstrec.getNumUniqueStrings(); k++)
    System.out.println("String table value " + k + " = " + sstrec.getString(k));
    break;
    case LabelSSTRecord.sid:
    LabelSSTRecord lrec = (LabelSSTRecord) record;
    System.out.println("String cell found with value " + sstrec.getString(lrec.getSSTIndex()));
    break;
         catch(Exception ex)
    * Read an excel file and spit out what we find.
    * @param args Expect one argument that is the file to read.
    * @throws IOException When there is an error processing the file.
    public static void main(String[] args) throws IOException
    // create a new file input stream with the input file specified
    // at the command line
         try
              FileInputStream fin = new FileInputStream("C:/FTERPending/FTER format.xls");
              // create a new org.apache.poi.poifs.filesystem.Filesystem
              POIFSFileSystem poifs = new POIFSFileSystem(fin);
              //      get the Workbook (excel part) stream in a InputStream
              InputStream din = poifs.createDocumentInputStream("Workbook");
              // construct out HSSFRequest object
              HSSFRequest req = new HSSFRequest();
              // lazy listen for ALL records with the listener shown above
              req.addListenerForAllRecords(new EventExample());
              // create our event factory
              HSSFEventFactory factory = new HSSFEventFactory();
              //      process our events based on the document input stream
              factory.processEvents(req, din);
              // once all the events are processed close our file input stream
              fin.close();
              // and our document input stream (don't want to leak these!)
              din.close();
              System.out.println("done.");
         catch(Exception ex)
    It prints correctly the output at the console and after that it throws an exception as
    java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
         at java.lang.reflect.Constructor.newInstance(Unknown Source)
         at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:224)
         at org.apache.poi.hssf.eventusermodel.HSSFEventFactory.genericProcessEvents(HSSFEventFactory.java:183)
         at org.apache.poi.hssf.eventusermodel.HSSFEventFactory.processEvents(HSSFEventFactory.java:101)
         at businessLogic.EventExample.main(EventExample.java:103)
    Caused by: java.lang.ArrayIndexOutOfBoundsException
         at java.lang.System.arraycopy(Native Method)
         at org.apache.poi.hssf.record.UnknownRecord.<init>(UnknownRecord.java:62)
         at org.apache.poi.hssf.record.SubRecord.createSubRecord(SubRecord.java:57)
         at org.apache.poi.hssf.record.ObjRecord.fillFields(ObjRecord.java:99)
         at org.apache.poi.hssf.record.Record.fillFields(Record.java:90)
         at org.apache.poi.hssf.record.Record.<init>(Record.java:55)
         at org.apache.poi.hssf.record.ObjRecord.<init>(ObjRecord.java:61)
         ... 8 more
    I am not getting why this exception is cming
    can anyone help me pls reply

    Does your Excel file has the "AutoFilter" activated?
    If that is the problem, you have here a solution for reading a file with AutoFilter : http://article.gmane.org/gmane.comp.jakarta.poi.user/4690

  • How to  read from excel file and write it using implicit jsp out object

    our code is as below:Please give us proper solution.
    we are reading from Excel file and writing in dynamicaly generated Excel file.it is writing but not as original excel sheet.we are using response.setContentType and response.setHeader for generating pop up for saveing the original file in to dynamically generated Excel file.
    <%@ page contentType="application/vnd.ms-excel" %>
    <%     
         //String dLoadFile = (String)request.getParameter("jspname1");
         String dLoadFile = "c:/purge_trns_nav.xls" ;
         File f = new File(dLoadFile);
         //set the content type(can be excel/word/powerpoint etc..)
         response.setContentType ("application/msexcel");
         //get the file name
         String name = f.getName().substring(f.getName().lastIndexOf("/") + 1,f.getName().length());
         //set the header and also the Name by which user will be prompted to save
         response.setHeader ("Content-Disposition", "attachment;     filename="+name);
         //OPen an input stream to the file and post the file contents thru the
         //servlet output stream to the client m/c
              FileInputStream in = new FileInputStream(f);
              //ServletOutputStream outs = response.getOutputStream();
              int bit = 10;
              int i = 0;
              try {
                        while (bit >= 0) {
                        bit = in.read();
                        out.write(bit) ;
    } catch (IOException ioe) { ioe.printStackTrace(System.out); }
              out.flush();
    out.close();
    in.close();     
    %>

    If you want to copy files as fast as possible, without processing them (as the DOS "copy" or the Unix "cp" command), you can try the java.nio.channels package.
    import java.nio.*;
    import java.nio.channels.*;
    import java.io.*;
    import java.util.*;
    import java.text.*;
    class Kopy {
         * @param args [0] = source filename
         *        args [1] = destination filename
        public static void main(String[] args) throws Exception {
            if (args.length != 2) {
                System.err.println ("Syntax: java -cp . Kopy source destination");
                System.exit(1);
            File in = new File(args[0]);
            long fileLength = in.length();
            long t = System.currentTimeMillis();
            FileInputStream fis = new FileInputStream (in);
            FileOutputStream fos = new FileOutputStream (args[1]);
            FileChannel fci = fis.getChannel();
            FileChannel fco = fos.getChannel();
            fco.transferFrom(fci, 0, fileLength);
            fis.close();
            fos.close();
            t = System.currentTimeMillis() - t;
            NumberFormat nf = new DecimalFormat("#,##0.00");
            System.out.print (nf.format(fileLength/1024.0) + "kB copied");
            if (t > 0) {
                System.out.println (" in " + t + "ms: " + nf.format(fileLength / 1.024 / t) + " kB/s");
    }

  • Opening an Excel File using Excel 97 from a JSP populated page(Urgent)

    Hello,
    I am using a JSP Page to populate data from the DB.
    When I am opening the same as an Excel File the JSP code is coming as the Excel page whenever Excel 97 is being used,but when Excel2000 or 2003 is being used then the data are coming as Excel formatted.I used the following code(JSP) :
    <head>
    <%
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition","inline; filename=ExtractData.xls");
    %>
    </head>

    I can't even tell what the difference is between "coming as the Excel page" and "coming as Excel formatted". But then when people make urgent posts they very rarely spend the time to describe the problem accurately. Why bother when it's so damn urgent?

  • Error reading excel file using POI.

    Hi ,
    I am having some problem when reading the excel file.
    While reading excel file I am getting error-java.io.IOException: Unable to read entire block; 4 bytes read; expected 512 bytes.
    part of my code:-
    InputStream stream = objFormFile.getInputStream();
    POIFSFileSystem fs = new POIFSFileSystem(stream);//getting above error here.
    HSSFWorkbook wb = new HSSFWorkbook(fs);
    Case 1:
    I download the file on the system ,save it ,and then directly upload it to the system ,I get the above error .
    Case 2:
    It works fine if I download the excel and manually open and save it and then upload it .
    I am using JDK1.4.1 and poi-2.5.1-final-20040804.jar.
    Can any one please help me out for the above problem?
    Edited by: hruday on Jul 31, 2008 3:20 AM

    Instead of using POIFSFileSystem, try to directly create the HSSFWorkbook
    InputStream stream = objFormFile.getInputStream();
    //POIFSFileSystem fs = new POIFSFileSystem( stream );//getting above error here.
    HSSFWorkbook wb = new HSSFWorkbook( stream );

  • Problem:  this mac is not reading an excell file after upgrading to yosemite.   My Mac is from 2009, it use to work perfectly but it wasn´t able to open some apps, thats why i upgrade it.   Now it once i donwload the zip it appears with an ".ods" ext

    Problem:  this mac is not reading an excell file after upgrading to yosemite.   My Mac is from 2009, it use to work perfectly but it wasn´t able to open some apps, thats why i upgrade it.   Now it once i donwload the zip it appears with an ".ods" extension
    i even already download a link
    http://www.microsoft.com/en-us/download/confirmation.aspx?id=44026
    which i read on another support page... but it doesnt allowed me to install it cause it says that i already have the disk of this program....
    Im afraid to erase it and not being able to get it back...
    What can i do!??
    Thanks in advance for this kind answer!!!

    fsolution wrote:
    Problem:  this mac is not reading an excell file after upgrading to yosemite...   Now it once i donwload the zip it appears with an ".ods" extension...
    If the "it" refers to a compressed (zipped) spreadsheet that you downloaded, the ".ods" extension is used by LibreOffice and probably OpenOffice (which are free versions of MS Office) for spreadsheets, which would suggest that wherever you're getting that "Excel" file from has switched to one of those programs. I've tried opening an .ods file from LibreOffice using MS Office 2013 for Windows and it does open though with a warning that some things have been changed. I don't know if Office for Mac can normally open .ods files. But if your need is to just open .ods files, take a look at LibreOffice.

Maybe you are looking for

  • Is there a way to import a Power Point presentation without adding click boxes?

    I want the user to navigate through the Power Point portion of my training by hitting one of two buttons.  Unfortunatley, in order for me to restrict the users options to these possibilities, I have to delete every click box from the slide that is ad

  • PerformancePoint Services is not configured correctly but I'm Site administrator

    Hi experts I recenlty create a business intelligence site and set my active directory user as administrator. I'm server and database administrator too. but when I want to create a data source I get this error: The Data source cannot be used because P

  • Integration Server URL for HTTPS

    I want to configure SSL for our PI 7.0 system.  I have: - Configured SSL on the Java Stack and tested it.  It works fine. - Configured SSL on the ABAP and tested it.  It works. I know to enable HTTPS I need to change the following exchange profile pa

  • Had photos in Photos App, took picture with Camera--All disappeared

    This happened in the last two weeks. Once I was able to have the photo albums go back to the iphone. Now, the second time this has happened, can not get the chosen albums in iTunes to sync to the iphone 3gs w/ 3.1.3 Is it me? Or is it the OS

  • Express Vi "Unable to view properties"

    I'm trying to create an express vi, but when I go to drop it on a block diagram I get the error: "Unable to view properties".  I've seen the online document "Placing an express vi causes 'unable to open properties' error" (http://digital.ni.com/publi