I have a web page where a user clicks on a link to generate xml file. I am generating this xml file inside a servlet and then writing it to the ServletOutputStream. This shows me a dialog box asking me to save or open the file. The save is working fine but when I open the file the xml file is opening in the same window. What I want is to open the file in a new window.
There are 3 options in dialog box save,open and cancel. When I select save its working fine, but when I select open in the dialog box it opens the file in the same browser window as my webpage. I want to open this file in a new Window.
This is browser issue, One need to check out any property/option in that browser which enable it to open html/xml in new tab/window.
One work around to this,
Put the link on JSP page, ask user to click on this link to get XML, then user clicks to link, it open in a new window (by using target="_blank"), link calls servlet, then user can view/download from that new window
I cannot set the target=_blank because it is not a link but its a button to generate the xml. The button submits the request to a servlet which generates the xml. I have set the content type as application/xml and content disposition as attachment for the response headers. But when I open the file from the dialog box it opens the file in the same browser window. I want to open it in a pop up.
amit kumar goyal wrote:
The button submits the request to a servlet which generates the XML. I have set the content type as application/xml and content disposition as attachment for the response headers. But when I open the file from the dialog box it opens the file in the same browser window.
This is the expected behavior from any browser, I already suggest one alternative to this. This is a browser behavior and you can't change it.
amit kumar goyal wrote:
I cannot set the target=_blank because it is not a link but its a button to generate the xml.
I want to open it in a pop up.
One solution, "submit" the action/path from JavaScript on "onclick()" event. Submit it by opening a pop window with the specified FORM action as a URL parameter in popup window. I never tried this but give it a try, also, If you modified your servlet to generate XML and return it as a string rather than stream, you won't asked for save/open message box , XML directly get displayed in popup window.
HTH
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted
0
amit kumar goyal wrote:Thankyou everybody for the replies....
I cannot set the target=_blank because it is not a link but its a button to generate the xml. The button submits the request to a servlet which generates the xml. I have set the content type as application/xml and content disposition as attachment for the response headers. But when I open the file from the dialog box it opens the file in the same browser window. I want to open it in a pop up.
You can still use target="_blank" for this. Set it in the <form>.