Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Problem with Exporting Data to Word

Reply
Thread Tools

Problem with Exporting Data to Word

 
 
Mux
Guest
Posts: n/a
 
      07-24-2006
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,men ubar=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

 
Reply With Quote
 
 
 
 
Vincent van Beveren
Guest
Posts: n/a
 
      07-24-2006
> function showRTF() {
> var newWin = window.open("",
> "newWin","width=900,height=800%,scrollbars=yes,men ubar=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.su bmit();',
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.sub mit();', 20);
}

Something like that.

Hope it helps,
Vincent
 
Reply With Quote
 
 
 
 
Mux
Guest
Posts: n/a
 
      07-25-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in Exporting ASP page in word Pankaj.3107@gmail.com ASP .Net Web Controls 0 07-19-2006 05:42 AM
Exporting data into Excel, Word in ASP.NET - Please help !!! bienwell ASP .Net 3 05-17-2005 07:49 PM
Exporting data into a MS Word Serial Letter via ASP.NET peteyjr ASP .Net 1 01-19-2005 08:03 PM
Exporting data into a MS Word Serial Letter via ASP peteyjr ASP General 1 01-18-2005 08:19 AM
Exporting data from (All columns in data grid EXCEPT THE 1st) to E =?Utf-8?B?cG11ZA==?= ASP .Net 2 01-10-2005 07:53 PM



Advertisments