Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

PDF/HTML browser problem  RSS feed

 
Emmanuel Pregnolato
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I re-open my thread locked
I have the following problem.
1) I open a PDf document in a browser. It's a servlet that generate (shoot) the PDF document.
2) If the user click on the refresh button a request is made to the servlet. The servlet validate the session. If the session is invalid I want to display a timeout page (jsp page).
3) The timeout page has to be displayed in the same window that I used to display the PDF. But I keep getting the pop up error message "File does not begin with %PDF-".
Even if I force the mime type to be "text/html".
Help.
Thanks.
 
Sam Walker
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know you can't show your timeout message in the same window where you had PDF open because that window is on the client side and the session can be validated on the server side.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam,
He's clicking 'refresh', so that gets him to the server-side. And the servlet emits the PDF, so it should be able to check the session.

Emmanuel,

What does your code that outputs back to the browser look like? Are you opening an output stream within your servlet and streaming the PDF directly? Are you outputting an HTML page that has an embedded PDF link?

The error message makes me think that the acrobat plugin is attempting to open and parse your "timed out" message, and of course, that 'file' isn't a PDF file, it's an HTML file.
 
Sam Walker
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mike,
I�m assuming that after the servlet finds a session is invalid the only thing that�s sent back to the client is a timeout message. What I�m saying is that message will be displayed in new browser window not the one that had PDF document showing.
 
Chad McGowan
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sam Walker:
Hi Mike,
I�m assuming that after the servlet finds a session is invalid the only thing that�s sent back to the client is a timeout message. What I�m saying is that message will be displayed in new browser window not the one that had PDF document showing.

If the refresh button is clicked, it sounds like a jsp is returning html content. Why wouldn't this display in the same window?
I think his problem lies in the way he is returning the html error message.
[ June 09, 2003: Message edited by: Chad McGowan ]
 
Sam Walker
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The content of the window is overridden with the new html page, at least that�s what I observed when I was working on my web site, may be I noted something wrong. I�d be interested to know if that�s not the case.
 
Nicholas Turner
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would if you cant find the culprit use one of those 65.00 pdf createors. I can look up the site name if you need it, thier out of africa and do a good job. or just create your own pdf file, using a tag library or rmi would be simple to make it dynamic and send that.
or not create the plugin values if its timed out.
Although I would think you would want to solve the first problem
my half a penny.
 
Emmanuel Pregnolato
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guy's, thanks for the support.
Let me explain further...
Here is my sequence.
1) User obtain a PDF in a browser,
(code below: if statement section).
2) The session falls into a timeout state.
3) User click refresh on the browser.
4) The servlet capture the refresh and validate the session.
5) Session is invalid => try to display an html error message instead of the PDF on the same window.
(code below: else statement section).
The problem occured at step 5: the browser window shown is blanc and a pop up window appear with the message "File does not begin with %PDF-".
Here is a sample of my code in my servlet.
===============================================
//Get the "channel"
OutputStream out = response.getOutputStream();
//Validate the session.
HttpSession session = request.getSession(false);
if(session != null && !session.isNew()){
response.setContentType("application/pdf");
//Retreive the Service Name.
response.setHeader("Content-disposition", "inline; filename=" + thispbn.getPDFFileName());
//Render the PDF.
thispbn.renderPDFResults(out);

}//if
else{
//Set the mime type and sub mime type to HTML.
response.setContentType("text/html");

//Retreive a new writer in function of the new assigned mime type.
out = response.getOutputStream();
out.print("time out message");
}//else
================================================
Thanks again for your help, hope it will clarify my problem.
 
Vladimir Ergovic
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your browser is IE it could be IE's bug, you should try to change extension to something like (display.pdf) or (display.html) because it is bug in explorer (it doesn't look to much in headers).
 
Emmanuel Pregnolato
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Vladimir pointed out it seems like a bug with IE and Acrobat.
I tried with Netscape and it work perfectly !!!
i.e.: The html page is displayed over the PDF.
Vladimir, I tried without success (with IE) the following peace of code:
response.setHeader("Content-disposition", "inline; filename=" + "error.html");
Again, it work with Netscape but not with IE, instead of having the blanc page with the pop up message, the browser freeze and my CPU usage jump to 100%. If I check the running processes I found Acrobat using all the CPU time. Why Acrobat is still in the portrait ?
Thanks.
 
Chad McGowan
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is a good point. Have you tried this with Netscape?
Also, for a quick fix, you can just forward the request to an error jsp page when the session times out. This will fix your problem.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if this will help or not, but I found a bit of a 'not incorrect, but not correct' coding in your posted code

You are calling getOutputStream() twice, and this might lead to odd behaviour. Again, I'm not sure, but you might try this, and see if it solves your problem...

[ June 10, 2003: Message edited by: Mike Curwen ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!