Display the content of .Doc file using JSP in html page

Discussion in 'Java' started by Rahul, Dec 19, 2006.

  1. Rahul

    Rahul Guest

    Hello All

    I want to open an MS word file in jsp page, and want to display the
    content on web page as html. The code I'm using is as follows :


    <%
    String fileName = "c:\\rahul\\test\\readingfile\\abc.doc";


    BufferedReader is = new BufferedReader(new FileReader(fileName));


    String fileData = "";


    while((fileData = is.readLine()) != null)
    {
    out.println(fileData);
    }
    %>


    But, the data is not printing in proper format.


    Please provide the solution.
    Rhanking you


    Rahul
    Rahul, Dec 19, 2006
    #1
    1. Advertising

  2. On 19 Dec 2006 02:05:11 -0800, Rahul wrote:
    > I want to open an MS word file in jsp page, and want to display the
    > content on web page as html. The code I'm using is as follows :


    [...]

    > But, the data is not printing in proper format.


    You have written code to read a plain text file, not a Word document.

    You need a library that understands the Word document format, for
    example this one:

    http://jakarta.apache.org/poi/index.html

    /gordon

    --
    [ don't email me support questions or followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
    Gordon Beaton, Dec 19, 2006
    #2
    1. Advertising

  3. Hi,

    Rahul wrote:
    > Hello All
    >
    > I want to open an MS word file in jsp page, and want to display the
    > content on web page as html. The code I'm using is as follows :
    > ...
    > But, the data is not printing in proper format.
    > ...
    > Please provide the solution.


    ROTFL!

    As you have already noticed, a Word/DOC-document is not a plain-text
    document. It is a binary format with many control- and formatting
    information. Unfortunately, it cannot easily be transformed to HTML!

    In short: There is no solution we can provide!

    A bit longer: Of course, there may be some good Java-Converters from DOC
    to HTML (although I do not know any (means: "any *good* one")). But I am
    sure there is no solution in 5 lines of code.

    You may take a look at the Apache FOP project, which deals ("tries to
    deal") with MS-Office formats, although I am not sure in how far you can
    read documents with it.

    But, again (in short): There is no solution (in general, for non-trivial
    documents).

    Ciao,
    Ingo
    Ingo R. Homann, Dec 19, 2006
    #3
  4. Rahul wrote:
    > Hello All


    Hello again. Please refrain from reposting topics,
    just because the first answer/s were not to your liking.

    If a thread starts badly, it is usually better to take it up
    back on the original thread.

    Andrew T.
    Andrew Thompson, Dec 19, 2006
    #4
  5. Rahul

    Alfred Guest

    Rahul wrote:
    > Hello All
    >
    > I want to open an MS word file in jsp page, and want to display the
    > content on web page as html. The code I'm using is as follows :
    >
    > <%
    > String fileName = "c:\\rahul\\test\\readingfile\\abc.doc";
    > BufferedReader is = new BufferedReader(new FileReader(fileName));
    > String fileData = "";
    > while((fileData = is.readLine()) != null)
    > {
    > out.println(fileData);
    > }
    > %>
    >
    > But, the data is not printing in proper format.


    Click on your brain, load a Word document with Notepad
    and look what happens.

    Alfred
    Alfred, Dec 22, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    3
    Views:
    497
    Tor Iver Wilhelmsen
    Sep 17, 2004
  2. DigitalUncle
    Replies:
    0
    Views:
    904
    DigitalUncle
    Nov 2, 2004
  3. novice via JavaKB.com
    Replies:
    8
    Views:
    14,830
    borgymanotoy
    Jun 5, 2009
  4. hazz
    Replies:
    6
    Views:
    49,541
    SkyUCHC
    Jun 9, 2010
  5. News123
    Replies:
    0
    Views:
    293
    News123
    Feb 6, 2010
Loading...

Share This Page