• 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

Javascript alert from PDF in JSP file

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am creating pdf from servlet. I need javascript alert for session time out on PDF file. The option is to generate pdf using jsp file.I am opening PDF in the same window (That's the requirement) I can't open it in new seperate window. Can anyone help me out with how to generate java script alert?
I tried to create pdf from jsp file I get following ----error "java.lang.IllegalStateException: getOutputStream() has already been called for this response"
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't generate or stream binary files like PDFs from a JSP page; use a servlet instead.

What do you mean by "session timeout" - what is the session that times out? If the generation of the PDF takes too long? Or something to do with server-side sesssions?
 
Medha Deshpande
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. I know using jsp is not good solution and I should use servlet... I wasn't sure how to access javascript from servlet on my pdf page.
I am using HttpSession i.e server side session. Let me explain what I mean. When server side session times out i.e 10 minutes for all pages in my application. I show javascript alert/dialogue saying "Session is timing out in 5 minutes". When user clicks OK it goes to session timed out page. and by clicking Cancel remains on the same page.
I want this alert/dialog to appear after 10 minues on my pdf page. As I start timer when I open the page using javascript. Can you please suggest some solution.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It isn't going to happen that way.

First of all, you have no way of knowing on the client how long is left before session timeout. And you have no way to find out. You could set up a JavaScript timer that could guess when the session timeout will occur, but it will just be a guess and not particularly accurate.

Secondly, there is no such thing as a "PDF page". If the browser is displaying a PDF in a window, there is no HTML page, and hence no way to run JavaScript.

You could perhaps be tricky and display the PDF in an iframe of a parent page, but that doesn't get around the fact that you don't know when the session will time out.

If a rough guess is good enough, then the iframe trick may be your best bet.
[ September 08, 2008: Message edited by: Bear Bibeault ]
 
Medha Deshpande
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What we do is when page is getting loaded (jsps) <body> onLoad() method we start javascript timer and after 10 minutes we show alert that your session is about to expire. I want such thing... I know you can do using

PdfWriter.addJavaScript("app.alert('Test',2);");

but somehow its not working for me. Can anyone please help.

Thanks,
Medha
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Huh... shows how much I know about deep and dark PDF stuff. I didn't know PDF had its own JavaScript API and capabilities. You might be better off searching for a forum on advanced PDF authoring.
[ September 08, 2008: Message edited by: Bear Bibeault ]
reply
    Bookmark Topic Watch Topic
  • New Topic