Problem with Exporting Data to Word

Discussion in 'Javascript' started by Mux, Jul 24, 2006.

  1. Mux

    Mux Guest

    I am facing the following problem while exporting data to Word.

    The current implementation is as described below:
    I have a JSP file which has a link that enables you to export the data
    to
    Word.
    Clicking on the link invokes a javascript function:
    function showRTF() {
    var newWin = window.open("",
    "newWin","width=900,height=800%,scrollbars=yes,menubar=yes,resizable=yes,too
    lbar=yes,location=no");
    window.document.formShowRTF.target="newWin";
    window.document.formShowRTF.submit();
    }

    and submits the form:
    <form name="formShowRTF" method="POST"
    action="http://<IP>/SampleApplication/servlet/mypackage.ExportServlet">
    <input type="hidden" name="RTFData" value="<%=strTemp%>" >

    Now submiting the form (POST operation)....invokes the Servlet which
    performs the export of the data.
    The data is passed as a hidden form parameter.

    The ExportServlet immplementation is as follows:

    public void doPost(HttpServletRequest request,
    HttpServletResponse response) throws ServletException,
    IOException
    {
    response.setContentType("application/msword");
    ServletOutputStream os =
    response.getOutputStream();

    String strTemp = request.getParameter("RTFData");

    if (strTemp==null)
    {
    strTemp = "No Data";
    }

    os.write(strTemp.getBytes());
    }


    Now let me explain the problem area:

    Exporting the data to word for the very first time, opens a popup
    window
    having an inline word document.
    Data gets exported to the word document within the popup window.
    Now, if i keep the popup window containing the data open, and i again
    request an export operation,
    i.e. i again click on the export to word link, this time the pop up
    window
    is not refreshed with the new data requested!!
    Whats happening surprisingly is, instead of calling the doPost() method
    of
    the Servlet, the doGet() method
    is invoked the second time when you request an export operation, with
    the
    popup window open.
    This is quite strange!!

    I have also tried opening different windows for every request.
    The problem with this approach is that the first window hangs or
    becomes
    blank.
    The first window displays the data, but its the earlier data and not
    the new
    requested data.
    The reason i guess is again same:
    the doGet() method is invoked the second time an export request is
    made,
    instead of doPost().
    Also, no data is fetched in the doGet() method.

    Another alternative is opening different Word docs for every request
    instead
    of an inline doc.
    However, I would like to know if there is a way to refresh the contents
    of
    the inline document using JScript that is already open within a browser
    window?

    Regards,
    Mukta
     
    Mux, Jul 24, 2006
    #1
    1. Advertising

  2. > function showRTF() {
    > var newWin = window.open("",
    > "newWin","width=900,height=800%,scrollbars=yes,menubar=yes,resizable=yes,too
    > lbar=yes,location=no");
    > window.document.formShowRTF.target="newWin";
    > window.document.formShowRTF.submit();
    > }
    >


    You might want to change that in window.open("about:blank" ...). Though
    as I recently learend, Opera does handle this correctly, firefox and
    internet explorer will not clear the document.

    Other than that the target seems to be static, so you might want to put
    that in the HTML.

    > Whats happening surprisingly is, instead of calling the doPost() method
    > of
    > the Servlet, the doGet() method
    > is invoked the second time when you request an export operation, with
    > the
    > popup window open.


    The window.open("" ...) _might_ cause a refresh with a GET.

    >
    > I have also tried opening different windows for every request.
    > The problem with this approach is that the first window hangs or
    > becomes blank.


    Have you used different window names?

    Well, it is rather strange, but it looks like what you did should work.
    I would atleast try opening with "about:blank". You might also want to
    implement a small delay between the submit and the opening of the window
    (using "window.setTimeout('window.document.formShowRTF.submit();',
    20)"). If possible, keep a reference to the window, so you don't need to
    open it twice:

    var docWin;

    function showRTF() {
    if (!docWin) {
    docWin = window.open("about:blank",
    "newWin", .. parameters... );
    } else {
    docWin.focus();
    }
    window.document.formShowRTF.target="newWin";
    window.setTimeout('window.document.formShowRTF.submit();', 20);
    }

    Something like that.

    Hope it helps,
    Vincent
     
    Vincent van Beveren, Jul 24, 2006
    #2
    1. Advertising

  3. Mux

    Mux Guest

    Hi,

    Thanks for replying to my query..

    Most of options have been tried like giving different window names.
    the about_blank tip is what i would have to try though...

    also the delay bit, i have given that a shot...howvever that aint a
    very good approach as it depends on the ntw speed.
    The desired effect may not always be possible.

    I will give this one more try, and let u knw.

    Thanks!
    Mukta
     
    Mux, Jul 25, 2006
    #3
    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. =?Utf-8?B?UHJhbmF2?=

    Exporting Images to Excel/Word

    =?Utf-8?B?UHJhbmF2?=, Apr 8, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    565
    =?Utf-8?B?UHJhbmF2?=
    Apr 8, 2004
  2. peteyjr
    Replies:
    1
    Views:
    654
    MWells
    Jan 19, 2005
  3. bienwell
    Replies:
    3
    Views:
    2,669
    bienwell
    May 17, 2005
  4. Problem in Exporting ASP page in word

    , Jul 19, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    150
  5. peteyjr
    Replies:
    1
    Views:
    260
    Bullschmidt
    Jan 18, 2005
Loading...

Share This Page