You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by David Johnson <ch...@gmail.com> on 2005/05/12 16:31:17 UTC

Opening a NEW browser for a 2nd content type from an action

Hey all

is it possible to forme my struts app to open up a second browser window for 
the purpose of streaming a different content type (like a pdf file) into it 
while maintaining the page in the original browser?

Essentially, I have a nicely rendered HTML report in browser "a" and when 
the user clicks "export to PDF" or "export to excel" I want a NEW browser to 
pop up into which I will send the response with the headerType set to the 
appropriate type.

the generation of the XL and PDF is handled for me, but the app flow is 
where Im foggy.

anyone done this?

-- 
-Dave
ChaChaNY@Gmail.com

Re: Opening a NEW browser for a 2nd content type from an action

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
As a general rule you always want to close any stream when done, unless 
you know by design that you need it to remain open, so yes, you probably 
want to close it.

That being said, I've seen *PLENTY* of code that does things like this 
that don't close the stream, and as far as I could tell it was 
well-behaved code otherwise... I suspect the container will close the 
stream at the end of the request processing cycle if it's still open, 
but I always close it to be certain.  Better to be explicit :)

Frank

David Johnson wrote:
> Wow, excellent. Thanks! is tehre anything IU need to do to close my 
> PrintWriter in the Action class? right now I have
> 
> response.setContentType("application/pdf");
> response.setHeader("Content-disposition", "inline" );
> PrintWriter out = response.getWriter();
> 
> socket.write(out); // I get my PDF through thtis socket
> 
> 
> 
> do I need to close() it explicitly?
> 
> On 5/12/05, Frank W. Zammetti <fz...@omnytex.com> wrote:
> 
>>Return null. That's it (seriously!) Null effectively means "do not
>>forward to anything, the response is completely formed".
>>
>>Frank
>>
>>David Johnson wrote:
>>
>>>Okay, I've got it opening the second browser (finally got back to it)
>>>using the target="_new" in the form declaration, but here's the real 
>>
>>problem
>>
>>>I'm in the action class, and I can can work on the response using
>>>
>>>response.setContentType("application/pdf");
>>>response.setHeader("Content-disposition", "inline" );
>>>
>>>BUT, when I get to the end of my action class, what do I return? I cant
>>>return to a JSP page because I've set the content type to be PDF (or 
>>
>>excel)
>>
>>>So, instead of
>>>
>>>mapping.findForward("success");
>>>
>>>what can I do?
>>>
>>>On 5/12/05, *Frank W. Zammetti* <fzlists@omnytex.com
>>><ma...@omnytex.com>> wrote:
>>>
>>>Ugh, I always forget the simple target attribute! Absolutely agreed,
>>>that's probably the best approach.
>>>
>>>--
>>>Frank W. Zammetti
>>>Founder and Chief Software Architect
>>>Omnytex Technologies
>>>http://www.omnytex.com
>>>
>>>On Thu, May 12, 2005 11:16 am, David Johnson said:
>>>
>>>>whoa that's simple. I'm trying that first!!!! Thanks
>>>>
>>>>One things though, I'll have to set the "target" conditionally,
>>>
>>>only when
>>>
>>>>the user clicks "PDF" or "EXCEL" since I dont **always** want it
>>>
>>>opening a
>>>
>>>>new window...
>>>>
>>>>function setTarget(target) {
>>>>document.forms[0].target=target;
>>>>}
>>>>
>>>>On 5/12/05, Aladin Alaily <struts@aladin.ca
>>>
>>><ma...@aladin.ca>> wrote:
>>>
>>>>>Hi Dave,
>>>>>
>>>>>This is pretty straightforward. In browser "a", you have a
>>>
>>>button that
>>>
>>>>>says:
>>>>>
>>>>>"Export to PDF"
>>>>>
>>>>>The code would look like this:
>>>>>
>>>>><html:form action="/exportToPdf.do" target="_NEW">
>>>>><submit name="export" value="Export to PDF">
>>>>></html>
>>>>>
>>>>>When the user clicks on the button, the action "exportToPdf.do"
>>>
>>>opens an
>>>
>>>>>ServletOutputStream and writes whatever you want. The headers
>>>
>>>are also
>>>
>>>>>set to the content-type you want and the format you want (inline or
>>>>>attachment).
>>>>>
>>>>>Aladin
>>>>>
>>>>>
>>>>>
>>>>>>Hey all
>>>>>>
>>>>>>is it possible to forme my struts app to open up a second browser
>>>>>
>>>>>window
>>>>>
>>>>>>for
>>>>>>the purpose of streaming a different content type (like a pdf
>>>
>>>file)
>>>
>>>>>into
>>>>>
>>>>>>it
>>>>>>while maintaining the page in the original browser?
>>>>>>
>>>>>>Essentially, I have a nicely rendered HTML report in browser
>>>
>>>"a" and
>>>
>>>>>when
>>>>>
>>>>>>the user clicks "export to PDF" or "export to excel" I want a NEW
>>>>>
>>>>>browser
>>>>>
>>>>>>to
>>>>>>pop up into which I will send the response with the headerType
>>>
>>>set to
>>>
>>>>>the
>>>>>
>>>>>>appropriate type.
>>>>>>
>>>>>>the generation of the XL and PDF is handled for me, but the
>>>
>>>app flow
>>>
>>>>>is
>>>>>
>>>>>>where Im foggy.
>>>>>>
>>>>>>anyone done this?
>>>>>>
>>>>>>--
>>>>>>-Dave
>>>>>>ChaChaNY@Gmail.com <ma...@Gmail.com>
>>>>>>
>>>>>
>>>>
>>>>--
>>>>-Dave
>>>>ChaChaNY@Gmail.com <ma...@Gmail.com>
>>>>
>>>
>>>
>>>
>>>--
>>>-Dave
>>>ChaChaNY@Gmail.com <ma...@Gmail.com>
>>
>>--
>>Frank W. Zammetti
>>Founder and Chief Software Architect
>>Omnytex Technologies
>>http://www.omnytex.com
>>
>>
> 
> 
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com


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


Re: Opening a NEW browser for a 2nd content type from an action

Posted by David Johnson <ch...@gmail.com>.
Wow, excellent. Thanks! is tehre anything IU need to do to close my 
PrintWriter in the Action class? right now I have

response.setContentType("application/pdf");
response.setHeader("Content-disposition", "inline" );
PrintWriter out = response.getWriter();

socket.write(out); // I get my PDF through thtis socket



do I need to close() it explicitly?

On 5/12/05, Frank W. Zammetti <fz...@omnytex.com> wrote:
> 
> Return null. That's it (seriously!) Null effectively means "do not
> forward to anything, the response is completely formed".
> 
> Frank
> 
> David Johnson wrote:
> > Okay, I've got it opening the second browser (finally got back to it)
> > using the target="_new" in the form declaration, but here's the real 
> problem
> >
> > I'm in the action class, and I can can work on the response using
> >
> > response.setContentType("application/pdf");
> > response.setHeader("Content-disposition", "inline" );
> >
> > BUT, when I get to the end of my action class, what do I return? I cant
> > return to a JSP page because I've set the content type to be PDF (or 
> excel)
> >
> > So, instead of
> >
> > mapping.findForward("success");
> >
> > what can I do?
> >
> > On 5/12/05, *Frank W. Zammetti* <fzlists@omnytex.com
> > <ma...@omnytex.com>> wrote:
> >
> > Ugh, I always forget the simple target attribute! Absolutely agreed,
> > that's probably the best approach.
> >
> > --
> > Frank W. Zammetti
> > Founder and Chief Software Architect
> > Omnytex Technologies
> > http://www.omnytex.com
> >
> > On Thu, May 12, 2005 11:16 am, David Johnson said:
> > > whoa that's simple. I'm trying that first!!!! Thanks
> > >
> > > One things though, I'll have to set the "target" conditionally,
> > only when
> > > the user clicks "PDF" or "EXCEL" since I dont **always** want it
> > opening a
> > > new window...
> > >
> > > function setTarget(target) {
> > > document.forms[0].target=target;
> > > }
> > >
> > > On 5/12/05, Aladin Alaily <struts@aladin.ca
> > <ma...@aladin.ca>> wrote:
> > >>
> > >> Hi Dave,
> > >>
> > >> This is pretty straightforward. In browser "a", you have a
> > button that
> > >> says:
> > >>
> > >> "Export to PDF"
> > >>
> > >> The code would look like this:
> > >>
> > >> <html:form action="/exportToPdf.do" target="_NEW">
> > >> <submit name="export" value="Export to PDF">
> > >> </html>
> > >>
> > >> When the user clicks on the button, the action "exportToPdf.do"
> > opens an
> > >> ServletOutputStream and writes whatever you want. The headers
> > are also
> > >> set to the content-type you want and the format you want (inline or
> > >> attachment).
> > >>
> > >> Aladin
> > >>
> > >>
> > >> > Hey all
> > >> >
> > >> > is it possible to forme my struts app to open up a second browser
> > >> window
> > >> > for
> > >> > the purpose of streaming a different content type (like a pdf
> > file)
> > >> into
> > >> > it
> > >> > while maintaining the page in the original browser?
> > >> >
> > >> > Essentially, I have a nicely rendered HTML report in browser
> > "a" and
> > >> when
> > >> > the user clicks "export to PDF" or "export to excel" I want a NEW
> > >> browser
> > >> > to
> > >> > pop up into which I will send the response with the headerType
> > set to
> > >> the
> > >> > appropriate type.
> > >> >
> > >> > the generation of the XL and PDF is handled for me, but the
> > app flow
> > >> is
> > >> > where Im foggy.
> > >> >
> > >> > anyone done this?
> > >> >
> > >> > --
> > >> > -Dave
> > >> > ChaChaNY@Gmail.com <ma...@Gmail.com>
> > >> >
> > >>
> > >>
> > >
> > >
> > > --
> > > -Dave
> > > ChaChaNY@Gmail.com <ma...@Gmail.com>
> > >
> >
> >
> >
> >
> > --
> > -Dave
> > ChaChaNY@Gmail.com <ma...@Gmail.com>
> 
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> 
> 


-- 
-Dave
ChaChaNY@Gmail.com

Re: Opening a NEW browser for a 2nd content type from an action

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Return null.  That's it (seriously!)  Null effectively means "do not 
forward to anything, the response is completely formed".

Frank

David Johnson wrote:
> Okay, I've got it opening the second browser (finally got back to it) 
> using the target="_new" in the form declaration, but here's the real problem
> 
> I'm in the action class, and I can can work on the response using
> 
> response.setContentType("application/pdf");
> response.setHeader("Content-disposition",  "inline" );
> 
> BUT, when I get to the end of my action class, what do I return? I cant 
> return to a JSP page because I've set the content type to be PDF (or excel)
> 
> So, instead of
> 
> mapping.findForward("success");
> 
> what can I do?
> 
> On 5/12/05, *Frank W. Zammetti* <fzlists@omnytex.com 
> <ma...@omnytex.com>> wrote:
> 
>     Ugh, I always forget the simple target attribute!  Absolutely agreed,
>     that's probably the best approach.
> 
>     --
>     Frank W. Zammetti
>     Founder and Chief Software Architect
>     Omnytex Technologies
>     http://www.omnytex.com
> 
>     On Thu, May 12, 2005 11:16 am, David Johnson said:
>      > whoa that's simple. I'm trying that first!!!! Thanks
>      >
>      > One things though, I'll have to set the "target" conditionally,
>     only when
>      > the user clicks "PDF" or "EXCEL" since I dont **always** want it
>     opening a
>      > new window...
>      >
>      > function setTarget(target) {
>      > document.forms[0].target=target;
>      > }
>      >
>      > On 5/12/05, Aladin Alaily <struts@aladin.ca
>     <ma...@aladin.ca>> wrote:
>      >>
>      >> Hi Dave,
>      >>
>      >> This is pretty straightforward. In browser "a", you have a
>     button that
>      >> says:
>      >>
>      >> "Export to PDF"
>      >>
>      >> The code would look like this:
>      >>
>      >> <html:form action="/exportToPdf.do" target="_NEW">
>      >> <submit name="export" value="Export to PDF">
>      >> </html>
>      >>
>      >> When the user clicks on the button, the action "exportToPdf.do"
>     opens an
>      >> ServletOutputStream and writes whatever you want. The headers
>     are also
>      >> set to the content-type you want and the format you want (inline or
>      >> attachment).
>      >>
>      >> Aladin
>      >>
>      >>
>      >> > Hey all
>      >> >
>      >> > is it possible to forme my struts app to open up a second browser
>      >> window
>      >> > for
>      >> > the purpose of streaming a different content type (like a pdf
>     file)
>      >> into
>      >> > it
>      >> > while maintaining the page in the original browser?
>      >> >
>      >> > Essentially, I have a nicely rendered HTML report in browser
>     "a" and
>      >> when
>      >> > the user clicks "export to PDF" or "export to excel" I want a NEW
>      >> browser
>      >> > to
>      >> > pop up into which I will send the response with the headerType
>     set to
>      >> the
>      >> > appropriate type.
>      >> >
>      >> > the generation of the XL and PDF is handled for me, but the
>     app flow
>      >> is
>      >> > where Im foggy.
>      >> >
>      >> > anyone done this?
>      >> >
>      >> > --
>      >> > -Dave
>      >> > ChaChaNY@Gmail.com <ma...@Gmail.com>
>      >> >
>      >>
>      >>
>      >
>      >
>      > --
>      > -Dave
>      > ChaChaNY@Gmail.com <ma...@Gmail.com>
>      >
> 
> 
> 
> 
> -- 
> -Dave
> ChaChaNY@Gmail.com <ma...@Gmail.com>

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com


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


Re: Opening a NEW browser for a 2nd content type from an action

Posted by David Johnson <ch...@gmail.com>.
Okay, I've got it opening the second browser (finally got back to it) using 
the target="_new" in the form declaration, but here's the real problem

I'm in the action class, and I can can work on the response using

response.setContentType("application/pdf");
response.setHeader("Content-disposition", "inline" ); 

BUT, when I get to the end of my action class, what do I return? I cant 
return to a JSP page because I've set the content type to be PDF (or excel)

So, instead of 

mapping.findForward("success");

what can I do?

On 5/12/05, Frank W. Zammetti <fz...@omnytex.com> wrote:
> 
> Ugh, I always forget the simple target attribute! Absolutely agreed,
> that's probably the best approach.
> 
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> 
> On Thu, May 12, 2005 11:16 am, David Johnson said:
> > whoa that's simple. I'm trying that first!!!! Thanks
> >
> > One things though, I'll have to set the "target" conditionally, only 
> when
> > the user clicks "PDF" or "EXCEL" since I dont **always** want it opening 
> a
> > new window...
> >
> > function setTarget(target) {
> > document.forms[0].target=target;
> > }
> >
> > On 5/12/05, Aladin Alaily <st...@aladin.ca> wrote:
> >>
> >> Hi Dave,
> >>
> >> This is pretty straightforward. In browser "a", you have a button that
> >> says:
> >>
> >> "Export to PDF"
> >>
> >> The code would look like this:
> >>
> >> <html:form action="/exportToPdf.do" target="_NEW">
> >> <submit name="export" value="Export to PDF">
> >> </html>
> >>
> >> When the user clicks on the button, the action "exportToPdf.do" opens 
> an
> >> ServletOutputStream and writes whatever you want. The headers are also
> >> set to the content-type you want and the format you want (inline or
> >> attachment).
> >>
> >> Aladin
> >>
> >>
> >> > Hey all
> >> >
> >> > is it possible to forme my struts app to open up a second browser
> >> window
> >> > for
> >> > the purpose of streaming a different content type (like a pdf file)
> >> into
> >> > it
> >> > while maintaining the page in the original browser?
> >> >
> >> > Essentially, I have a nicely rendered HTML report in browser "a" and
> >> when
> >> > the user clicks "export to PDF" or "export to excel" I want a NEW
> >> browser
> >> > to
> >> > pop up into which I will send the response with the headerType set to
> >> the
> >> > appropriate type.
> >> >
> >> > the generation of the XL and PDF is handled for me, but the app flow
> >> is
> >> > where Im foggy.
> >> >
> >> > anyone done this?
> >> >
> >> > --
> >> > -Dave
> >> > ChaChaNY@Gmail.com
> >> >
> >>
> >>
> >
> >
> > --
> > -Dave
> > ChaChaNY@Gmail.com
> >
> 
> 


-- 
-Dave
ChaChaNY@Gmail.com

Re: Opening a NEW browser for a 2nd content type from an action

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Ugh, I always forget the simple target attribute!  Absolutely agreed,
that's probably the best approach.

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

On Thu, May 12, 2005 11:16 am, David Johnson said:
> whoa that's simple. I'm trying that first!!!! Thanks
>
> One things though, I'll have to set the "target" conditionally, only when
> the user clicks "PDF" or "EXCEL" since I dont **always** want it opening a
> new window...
>
> function setTarget(target) {
> document.forms[0].target=target;
> }
>
> On 5/12/05, Aladin Alaily <st...@aladin.ca> wrote:
>>
>> Hi Dave,
>>
>> This is pretty straightforward. In browser "a", you have a button that
>> says:
>>
>> "Export to PDF"
>>
>> The code would look like this:
>>
>> <html:form action="/exportToPdf.do" target="_NEW">
>> <submit name="export" value="Export to PDF">
>> </html>
>>
>> When the user clicks on the button, the action "exportToPdf.do" opens an
>> ServletOutputStream and writes whatever you want. The headers are also
>> set to the content-type you want and the format you want (inline or
>> attachment).
>>
>> Aladin
>>
>>
>> > Hey all
>> >
>> > is it possible to forme my struts app to open up a second browser
>> window
>> > for
>> > the purpose of streaming a different content type (like a pdf file)
>> into
>> > it
>> > while maintaining the page in the original browser?
>> >
>> > Essentially, I have a nicely rendered HTML report in browser "a" and
>> when
>> > the user clicks "export to PDF" or "export to excel" I want a NEW
>> browser
>> > to
>> > pop up into which I will send the response with the headerType set to
>> the
>> > appropriate type.
>> >
>> > the generation of the XL and PDF is handled for me, but the app flow
>> is
>> > where Im foggy.
>> >
>> > anyone done this?
>> >
>> > --
>> > -Dave
>> > ChaChaNY@Gmail.com
>> >
>>
>>
>
>
> --
> -Dave
> ChaChaNY@Gmail.com
>


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


Re: Opening a NEW browser for a 2nd content type from an action

Posted by David Johnson <ch...@gmail.com>.
whoa that's simple. I'm trying that first!!!! Thanks

One things though, I'll have to set the "target" conditionally, only when 
the user clicks "PDF" or "EXCEL" since I dont **always** want it opening a 
new window... 

function setTarget(target) {
document.forms[0].target=target;
}

On 5/12/05, Aladin Alaily <st...@aladin.ca> wrote:
> 
> Hi Dave,
> 
> This is pretty straightforward. In browser "a", you have a button that 
> says:
> 
> "Export to PDF"
> 
> The code would look like this:
> 
> <html:form action="/exportToPdf.do" target="_NEW">
> <submit name="export" value="Export to PDF">
> </html>
> 
> When the user clicks on the button, the action "exportToPdf.do" opens an
> ServletOutputStream and writes whatever you want. The headers are also
> set to the content-type you want and the format you want (inline or
> attachment).
> 
> Aladin
> 
> 
> > Hey all
> >
> > is it possible to forme my struts app to open up a second browser window
> > for
> > the purpose of streaming a different content type (like a pdf file) into
> > it
> > while maintaining the page in the original browser?
> >
> > Essentially, I have a nicely rendered HTML report in browser "a" and 
> when
> > the user clicks "export to PDF" or "export to excel" I want a NEW 
> browser
> > to
> > pop up into which I will send the response with the headerType set to 
> the
> > appropriate type.
> >
> > the generation of the XL and PDF is handled for me, but the app flow is
> > where Im foggy.
> >
> > anyone done this?
> >
> > --
> > -Dave
> > ChaChaNY@Gmail.com
> >
> 
> 


-- 
-Dave
ChaChaNY@Gmail.com

Re: Opening a NEW browser for a 2nd content type from an action

Posted by Aladin Alaily <st...@aladin.ca>.
Hi Dave,

This is pretty straightforward.  In browser "a", you have a button that says:

"Export to PDF"

The code would look like this:

<html:form action="/exportToPdf.do" target="_NEW">
  <submit name="export" value="Export to PDF">
</html>

When the user clicks on the button, the action "exportToPdf.do" opens an
ServletOutputStream and writes whatever you want.  The headers are also
set to the content-type you want and the format you want (inline or
attachment).

Aladin



> Hey all
>
> is it possible to forme my struts app to open up a second browser window
> for
> the purpose of streaming a different content type (like a pdf file) into
> it
> while maintaining the page in the original browser?
>
> Essentially, I have a nicely rendered HTML report in browser "a" and when
> the user clicks "export to PDF" or "export to excel" I want a NEW browser
> to
> pop up into which I will send the response with the headerType set to the
> appropriate type.
>
> the generation of the XL and PDF is handled for me, but the app flow is
> where Im foggy.
>
> anyone done this?
>
> --
> -Dave
> ChaChaNY@Gmail.com
>


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