aspose file tools*
The moose likes JSP and the fly likes Javascript alert from PDF in JSP file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Javascript alert from PDF in JSP file" Watch "Javascript alert from PDF in JSP file" New topic
Author

Javascript alert from PDF in JSP file

Medha Deshpande
Greenhorn

Joined: Sep 08, 2008
Posts: 4
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"
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39571
    
  27
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?


Ping & DNS - updated with new look and Ping home screen widget
Medha Deshpande
Greenhorn

Joined: Sep 08, 2008
Posts: 4
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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60071
    
  65

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Medha Deshpande
Greenhorn

Joined: Sep 08, 2008
Posts: 4
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60071
    
  65

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javascript alert from PDF in JSP file
 
Similar Threads
Alert after completion of download.
Accessing JavaMethod from javascript
Javascript code inside JSP (error in flushing)
Error opening pdf file from modal window
Problem in opening PDF file in client browser