Javascript alert from PDF in JSP file

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"

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

Joined: Sep 08, 2008
Posts: 4

posted Sep 08, 2008 10:07:00

0

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.

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 ]

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

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 ]