• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

to open new window from a servlet

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

is it possible to open a new window from a servlet?

Actually i want to show a message "please wait..." in new window while servlet is doing some processing !
I have the code to display the "please wait message..." on the screen it self ...but the problem is that, my servlet is used for reading a file(doc,pdf,xls,text,html) from server. so if i display the message in servlet page itself like below -




so if i used the above code, the message gets displayed on the page. but the window should get closed automatically when the xls/doc file is open.

Please help !!
 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After the response text is sent back to the client, there's nothing you can do with it. So basically, once you close the PrintWriter instance, the response body is sent back to the client while you keep working with the OutputStream associated with the response. When you close the stream, you can't do anything about the page's display content.
Personally I don't think it's wise to work on both the PrintWriter and OutputStream associated with a HTTPServletResponse instance. More often than not, one gets to bump into an IllegalStateException.

What you should probably try to do is - when you send the control to this servlet, display the message on the screen at that point while you submit the request to this particular servlet. For eg - if you come here from a JSP, in your JSP you can write a small JavaScript snippet which directs the user's browser to a static HTML using something like - Thereafter, you can simply submit the JSP's form object. [your form object's action attribute should map to this servlet].
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interesting solution Arnivan, however I am not sure about the implementation of it - when you reset the location.href are you appending all the form values and the submitting the form from the new page? Presumably with the entire form being hidden on the new page.

Personally I would submit the form as normal, and have the receiving servlet pass off the majority of the work to a pool of worker threads. The servlet is then free to return almost instantly to a screen that says "please wait". This new screen would then spawn an Ajax request to get the real response from the server once the worker thread completed.
 
Anirvan Majumdar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Andrew, it works although it sounds a bit strange. location.href simply changes the display page and doesn't submit the form. A snippet like this -
will display the HTML page while submitting the form to the servlet. When the servlet sends back its response, the browser will refresh with the servlet's content. I think the only limiting factor about this is that the time taken by the servlet to send back the response > time taken for moving to the HTML page [which usually is the case].
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Thanks for explaining.
 
manisha Gupta Garg
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Arivan and Andrew, for your interest!!

but my problem is xls,pdf reports have to be open in their native application and our code and property of IE does this. so if they open in microsoft applications and if we have applied something like the approaches i mentioend in my post and the approaches that you folks are suggesting then the jsp which has opened the servlet to read the file, would remain open as it is and we want to close the jsp/servlet page when the report is openned.

Please help!

Thanks,
Manisha
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The same basic approaches can be used.

You could have a secondary servlet tracking whether the report has been sent or not

Use Anirvan's suggestion to get the temporary page displaying, and have that page generate an Ajax request every 'x' seconds to the secondary servlet to check the status - if the report has been sent then the tab can close itself.
reply
    Bookmark Topic Watch Topic
  • New Topic