Servlet genereate PDF called twice

Discussion in 'Java' started by Dev, Apr 8, 2004.

  1. Dev

    Dev Guest

    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
    Dev, Apr 8, 2004
    #1
    1. Advertising

  2. 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


    "Dev" <> wrote in message news:<c53aqr$2ofs8j$-berlin.de>...
    > 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
    Michael Scovetta, Apr 8, 2004
    #2
    1. Advertising

  3. 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


    "Dev" <> schrieb im Newsbeitrag
    news:c53aqr$2ofs8j$-berlin.de...
    > 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
    >
    >
    Clemens Martin, Apr 8, 2004
    #3
  4. Dev

    Dev Guest

    "Michael Scovetta" <> ha scritto nel
    messaggio news:...
    > 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.
    Dev, Apr 9, 2004
    #4
  5. Dev

    Jayaram Guest

    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...


    "Dev" <> wrote in message news:<c53aqr$2ofs8j$-berlin.de>...
    > 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
    Jayaram, Apr 9, 2004
    #5
  6. Dev

    Dev Guest

    "Jayaram" <> ha scritto nel messaggio
    news:...
    > 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)
    Dev, Apr 9, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. circuit_breaker
    Replies:
    2
    Views:
    1,978
    Jack Jia
    Apr 4, 2004
  2. Dev

    servlet called twice

    Dev, Apr 27, 2004, in forum: Java
    Replies:
    5
    Views:
    3,319
    Joris Van den Bogaert
    May 3, 2004
  3. Kiuhnm

    twice(twice(x))

    Kiuhnm, Apr 1, 2006, in forum: C++
    Replies:
    2
    Views:
    384
    Kiuhnm
    Apr 1, 2006
  4. Ricardo Pog
    Replies:
    1
    Views:
    395
    Austin Ziegler
    Mar 26, 2008
  5. Sean Nakasone
    Replies:
    1
    Views:
    337
    Farrel Lifson
    Apr 14, 2008
Loading...

Share This Page