Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Open an XML file in a popup window

 
amit kumar goyal
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello .......

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.

Thanks.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, You mean when you save a file on a system and then open it, it gets open in "browser" which dosen't support "tabs" ?
 
amit kumar goyal
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use target="_blank" in the link.
 
amit kumar goyal
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bauke Scholtz wrote:
You can still use target="_blank" for this. Set it in the <form>.

That's indeed a good solution, But as per this link, its use is deprecated, instead open a action URL in new/popup window.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic