Problem with Exporting Data to Word

M

Mux

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
 
V

Vincent van Beveren

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
 
M

Mux

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top