struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton" <niall.pember...@blueyonder.co.uk>
Subject Re: RE : problem with returning a pdf
Date Tue, 22 Jun 2004 21:40:24 GMT
A couple of comments - I'm streaming pdf files and using IE6 and my action
is only called once - are you sure its not a pre IE6 issue?

Secondly - what about implementing this behaviour in the request processor.
You could customise ActionMapping to add a contentType property - when
required you set this in the struts-config.xml for your Action - so in your
case set it to "application/pdf". The in your custom RequestProcessor if the
ActionMappings content type has been set and the "user-agent" is "contype"
then set the content type to the value specified and return. I've put sample
code for this below...


** Create your own custom ActionMapping and add a "contentType" property
with appropriate getters/setters.

** Create your own custom RequestProcessor and override the processMapping()
method - if the contentType property has been set for the ActionMapping,
then do your check

   protected ActionMapping processMapping(HttpServletRequest request,
                                           HttpServletResponse response,
                                           String path)

       ActionMapping  mapping = super.processMapping(request, response,
path);

       if (mapping == null || !(mapping instancof MyActionMapping))
           return mapping;

      // get content type set in struts-config.xml
      String contentType = ((MyActionMapping)mapping).getContentType();

      //the user-agent is set to contype only for the first request
      if (contentType != null &&
           request.getHeader("user-agent").equals("contype")) {
        response.setContentType(contentType);
        response.setStatus(HttpServletResponse.SC_OK);
        return null;
     }

     return mapping;

  }

** Configure Struts to use your custom ActionMapping class and set the
contentType property on the appropriate mapping. In the struts-config.xml

   <action-mappings className="myPackage.MyActionMapping">
       <action......>
            <set-property property="contentType" value="application/pdf"/>
       </action>
   </action-mappings>

** Configure Struts to use your custom RequestProcessor. In the
struts-config.xml

  <controller processorClass="myPackage.myRequestProcessor"/>

Niall


----- Original Message ----- 
From: "tvvincam" <tvvincam@yahoo.com>
To: <struts-user@jakarta.apache.org>
Sent: Tuesday, June 22, 2004 2:43 AM
Subject: Re: RE : problem with returning a pdf


Thanks for your help Frank, Davlid, Shayam,

Unfortunatly, non of the solutions worked.

I renamed my reset method in the form bean and am calling it manually
at the end of the action - this stops the booleans from being reset
when IE resubmits the request. Dodgy but it works.

Also, there was a bit of code on java.sun.com forum which helps to
stop the action from processing all the business logic 3 times, but
execute method is still called 3 times:

//work-around for IE streaming pdf bug
//http://support.microsoft.com/default.aspx?scid=kb;EN-US;q293792
String accLang = request.getHeader("accept-language");
String theAgent = request.getHeader("user-agent");

//the user-agent is set to contype only for the first request
if (request.getHeader("user-agent").equals("contype")) {
   response.setContentType("application/pdf");
   response.setStatus(HttpServletResponse.SC_OK);
   return null;
}

// IE 5.5 and IE 6 only has an accept-language header on the first
request so if present
// ignore this request
if (theAgent.indexOf("MSIE") != -1) {
 if (accLang != null) {
   response.setContentType("application/pdf");
   response.setStatus
(HttpServletResponse.SC_OK);
   return null;
 }
}

Cheers,
N



--- In struts@yahoogroups.com, "David Gagnon" <dgagnon@a...> wrote:
> Hi,
>
>  You can also look how FOP work around this problem:
>
> http://xml.apache.org/fop/faq.html#iex-servlet-multiple
>
> /David
>
> -----Message d'origine-----
> De : tvvincam [mailto:tvvincam@y...]
> Envoyé : June 20, 2004 22:22
> À : struts-user@j...
> Objet : problem with returning a pdf
>
> Hi,
>
> I'm using JasperReports to create a pdf based on user criteria
> submitted via a struts form.
>
> I've run into a problem with a feature in IE
> http://support.microsoft.com/default.aspx?scid=kb;EN-US;q293792
>
> Basically, IE will resubmit the request 3 times. This is causing a
> problem because the reset method is called on my form bean and
wipes
> out all my boolean selection criteria.
>
> The iText web site http://www.lowagie.com/iText/faq.html#msie
> has the following work around:
> <HTML>
> <BODY leftMargin=0 topMargin=0 scroll=no>
>   <EMBED src="http://myserver/pdfCreationServlet" width="100%"
> height="100%" type=application/pdf fullscreen="yes">
> </body>
> </html>
>
> but I cannot figure out how to get the user input using this method.
>
> Is there a way around this problem? The only way I can think of
doing
> is to save the pdf byte[] in session and then get redirect the user
> to the above work around page. The above link will point to another
> action which will get the pdf byte[] from session and write it to
the
> response. I really don't like this solution and would appreciate
any
> help.
>
> Cheers,
> N
>
>
> --------------------------------------------------------------------
-
> To unsubscribe, e-mail: user-unsubscribe@s...
> For additional commands, e-mail: user-help@s...
>
>
>
> --------------------------------------------------------------------
-
> To unsubscribe, e-mail: user-unsubscribe@s...
> For additional commands, e-mail: user-help@s...


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message