Servlet genereate PDF called twice

D

Dev

Hi all, I have a web page, and in a link, with a JavaScript I open a new
window, then I change the url of the new window.

the new URL is a servlet call.

The response of the servlet is a PDF.

The problem is that servlet was called twice!
In the form on the page where there are the javascript there are no action
attribute.

I have tried to open the new window with
var vNewWin = window.open("/servlet/PrintPDFServlet?param.....",
name,option);
but the browser try to download a page /servlet/PrintPDFServlet?param.....
but witout success.

Anyone have some idea?

Thanks in advance.

Dev
 
M

Michael Scovetta

I would suggest checking it with wfetch (from Microsoft). See exactly
what is being sent and what is being received. Is the servlet being
init()ed correctly? If it throws an exception, it'll re-init(). Are
you calling it from a forward() or something internal as well as from
/servlets/... ? I've had this only happen once, and it was actually my
Tomcat filters executing twice-- once for the request to / and once
for the request to /index.jsp (it was my default page setup in
web.xml).

It might also be a content-type issue-- is any other data being sent
as well as the PDF?

Hope that help a bit.

Michael Scovetta
 
C

Clemens Martin

Hi,

is the content-type set correctly in the HttpServletResponse
(application/pdf, i think)?
Which kind of servlet-engine and version?
I also think to remember there is some thing with HTTP header "no-cache" and
such things, try to google for that.

Try to figure out if it's the same problem in Netscape and/or IE and google
again.

Hope that helps a little bit,

Clemens Martin
 
D

Dev

Michael Scovetta said:
I would suggest checking it with wfetch (from Microsoft). See exactly
what is being sent and what is being received. Is the servlet being
init()ed correctly?
Yes

If it throws an exception, it'll re-init().

No exceoption rised
Are you calling it from a forward() or something internal as well as from
/servlets/... ?

I call a servlet from Javascript code: I set the window.location.href to
/servlet/printPDFServlet?param1=qqqq&param2=...

I've had this only happen once, and it was actually my
Tomcat filters executing twice-- once for the request to / and once
for the request to /index.jsp (it was my default page setup in
web.xml).

It might also be a content-type issue-- is any other data being sent
as well as the PDF?

I have set the content-type to apllication/pdf
Hope that help a bit.

Michael Scovetta

Thanks

Federico.
 
J

Jayaram

Dev,
Are you using Internet Explorer ? There is a bug in IE that causes the
browser to automatically send two requests for a dynamically generated
PDF document. You would notice that this doesnt happen in Netscape
browsers.
The workaround in IE is to use the html emebd tag:

<EMBED src="your servlet url" contentType = "application/pdf">

(the syntax above may not be correct - find out more about this on an
HTML reference guide)

Regards,
J...
 
D

Dev

Jayaram said:
Dev,
Are you using Internet Explorer ?
Yes!

There is a bug in IE that causes the
browser to automatically send two requests for a dynamically generated
PDF document. You would notice that this doesnt happen in Netscape
browsers.
The workaround in IE is to use the html emebd tag:

<EMBED src="your servlet url" contentType = "application/pdf">

(the syntax above may not be correct - find out more about this on an
HTML reference guide)

Tanks a lot.
Regards,
J...

Good Easter!

Dev (Aka Federico)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top