You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by bhaarat Sharma <bh...@gmail.com> on 2008/03/18 02:59:41 UTC

Struts 1 return stream (documents)

Hello,

I started struts by learning struts2.  However, now i am working with
struts 1: (

I am faced with a problem where user downloads a file.

I have this in the struts.xml

		<action path="/viewModificationDocument"
			type="org.something1.something2.actions.download.ModificationDocumentDownloadAction"
			scope="request" input="viewAwardModification">
		</action>

And then in the action I have this which is returning a bytestream

	protected class ByteArrayStreamInfo implements StreamInfo {

		protected String contentType;

		protected byte[] bytes;

		public ByteArrayStreamInfo(String contentType, byte[] bytes) {
			this.contentType = contentType;
			this.bytes = bytes;
		}

		public String getContentType() {
			return contentType;
		}

		public InputStream getInputStream() throws IOException {
			return new ByteArrayInputStream(bytes);
		}

	}

But when user clicks a link is sees a open close cancel dialog
box...he just sees <actionname>.do as file name.  I know I am not
returning the file name (I can) but where will I catch it?? like in
struts 2...shouldnt tehre be more in the action of this? like
specifying what is returned? and if i return the name.....should I
just make public String getFileName() method in ByteArrayStreamInfo
class?

Thanks!

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


RE: Re: Struts 1 return stream (documents)

Posted by "Griffith, Michael *" <Mi...@fda.hhs.gov>.
Forgive me if I am on the wrong track here, I think I picked up this
thread in the middle... but I think I would answer:

> How are we suppose to supply the fileName?

By setting a response header:

response.setHeader("Content-Disposition", "inline;filename="foo.xyz");

MG

-----Original Message-----
From: news [mailto:news@ger.gmane.org] On Behalf Of Laurie Harper
Sent: Tuesday, March 18, 2008 9:48 AM
To: user@struts.apache.org
Subject: Re: Struts 1 return stream (documents)

The techniques shown in the earlier examples would work equally well in 
the byte stream example. How you determine the source of the data to 
send back to the browser is really up to you.

- configure it statically in struts-config.xml (as per the first two 
exxamples

- take it from a request parameter

- derive it from some other user or request data

L.

bhaarat Sharma wrote:
> Quick question
> 
> in all other examples on that page they show how the fileName is
> retrieved. But for Byte Array Example they do not mention anything
> regarding the fileName.
> 
> How are we suppose to supply the fileName?
> 
> 
> On Mon, Mar 17, 2008 at 10:41 PM, Dave Newton <ne...@yahoo.com>
wrote:
>> --- bhaarat Sharma <bh...@gmail.com> wrote:
>>
>>> Thanks! I remember you helped me with similar problem in S2 as well
>>  I'm very good at using the work of others to make me look good ;)
>>
>>  Dave
>>
>>
>>
>>
>>
---------------------------------------------------------------------
>>  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


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


Re: Struts 1 return stream (documents)

Posted by Laurie Harper <la...@holoweb.net>.
The techniques shown in the earlier examples would work equally well in 
the byte stream example. How you determine the source of the data to 
send back to the browser is really up to you.

- configure it statically in struts-config.xml (as per the first two 
exxamples

- take it from a request parameter

- derive it from some other user or request data

L.

bhaarat Sharma wrote:
> Quick question
> 
> in all other examples on that page they show how the fileName is
> retrieved. But for Byte Array Example they do not mention anything
> regarding the fileName.
> 
> How are we suppose to supply the fileName?
> 
> 
> On Mon, Mar 17, 2008 at 10:41 PM, Dave Newton <ne...@yahoo.com> wrote:
>> --- bhaarat Sharma <bh...@gmail.com> wrote:
>>
>>> Thanks! I remember you helped me with similar problem in S2 as well
>>  I'm very good at using the work of others to make me look good ;)
>>
>>  Dave
>>
>>
>>
>>
>>  ---------------------------------------------------------------------
>>  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


Re: Struts 1 return stream (documents)

Posted by bhaarat Sharma <bh...@gmail.com>.
Quick question

in all other examples on that page they show how the fileName is
retrieved. But for Byte Array Example they do not mention anything
regarding the fileName.

How are we suppose to supply the fileName?


On Mon, Mar 17, 2008 at 10:41 PM, Dave Newton <ne...@yahoo.com> wrote:
> --- bhaarat Sharma <bh...@gmail.com> wrote:
>
> > Thanks! I remember you helped me with similar problem in S2 as well
>
>  I'm very good at using the work of others to make me look good ;)
>
>  Dave
>
>
>
>
>  ---------------------------------------------------------------------
>  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


Re: Struts 1 return stream (documents)

Posted by Dave Newton <ne...@yahoo.com>.
--- bhaarat Sharma <bh...@gmail.com> wrote:
> Thanks! I remember you helped me with similar problem in S2 as well

I'm very good at using the work of others to make me look good ;)

Dave


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


Re: Struts 1 return stream (documents)

Posted by bhaarat Sharma <bh...@gmail.com>.
yes, that worked!

Thanks! I remember you helped me with similar problem in S2 as well

On Mon, Mar 17, 2008 at 10:07 PM, Dave Newton <ne...@yahoo.com> wrote:
> Does this help?
>
>  http://wiki.apache.org/struts/StrutsFileDownload
>
>  Dave
>
>
>
>  --- bhaarat Sharma <bh...@gmail.com> wrote:
>
>  > Hello,
>  >
>  > I started struts by learning struts2.  However, now i am working with
>  > struts 1: (
>  >
>  > I am faced with a problem where user downloads a file.
>  >
>  > I have this in the struts.xml
>  >
>  >               <action path="/viewModificationDocument"
>  >
>  >
>  type="org.something1.something2.actions.download.ModificationDocumentDownloadAction"
>  >                       scope="request" input="viewAwardModification">
>  >               </action>
>  >
>  > And then in the action I have this which is returning a bytestream
>  >
>  >       protected class ByteArrayStreamInfo implements StreamInfo {
>  >
>  >               protected String contentType;
>  >
>  >               protected byte[] bytes;
>  >
>  >               public ByteArrayStreamInfo(String contentType, byte[] bytes) {
>  >                       this.contentType = contentType;
>  >                       this.bytes = bytes;
>  >               }
>  >
>  >               public String getContentType() {
>  >                       return contentType;
>  >               }
>  >
>  >               public InputStream getInputStream() throws IOException {
>  >                       return new ByteArrayInputStream(bytes);
>  >               }
>  >
>  >       }
>  >
>  > But when user clicks a link is sees a open close cancel dialog
>  > box...he just sees <actionname>.do as file name.  I know I am not
>  > returning the file name (I can) but where will I catch it?? like in
>  > struts 2...shouldnt tehre be more in the action of this? like
>  > specifying what is returned? and if i return the name.....should I
>  > just make public String getFileName() method in ByteArrayStreamInfo
>  > class?
>  >
>  > Thanks!
>  >
>  > ---------------------------------------------------------------------
>  > 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
>
>

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


Re: Struts 1 return stream (documents)

Posted by Dave Newton <ne...@yahoo.com>.
Does this help?

http://wiki.apache.org/struts/StrutsFileDownload

Dave

--- bhaarat Sharma <bh...@gmail.com> wrote:

> Hello,
> 
> I started struts by learning struts2.  However, now i am working with
> struts 1: (
> 
> I am faced with a problem where user downloads a file.
> 
> I have this in the struts.xml
> 
> 		<action path="/viewModificationDocument"
> 		
>
type="org.something1.something2.actions.download.ModificationDocumentDownloadAction"
> 			scope="request" input="viewAwardModification">
> 		</action>
> 
> And then in the action I have this which is returning a bytestream
> 
> 	protected class ByteArrayStreamInfo implements StreamInfo {
> 
> 		protected String contentType;
> 
> 		protected byte[] bytes;
> 
> 		public ByteArrayStreamInfo(String contentType, byte[] bytes) {
> 			this.contentType = contentType;
> 			this.bytes = bytes;
> 		}
> 
> 		public String getContentType() {
> 			return contentType;
> 		}
> 
> 		public InputStream getInputStream() throws IOException {
> 			return new ByteArrayInputStream(bytes);
> 		}
> 
> 	}
> 
> But when user clicks a link is sees a open close cancel dialog
> box...he just sees <actionname>.do as file name.  I know I am not
> returning the file name (I can) but where will I catch it?? like in
> struts 2...shouldnt tehre be more in the action of this? like
> specifying what is returned? and if i return the name.....should I
> just make public String getFileName() method in ByteArrayStreamInfo
> class?
> 
> Thanks!
> 
> ---------------------------------------------------------------------
> 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