struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kelly.Graus" <>
Subject Re: [S2] Multiple SUCCESS results?
Date Wed, 12 Mar 2008 20:08:59 GMT

Wes Wannemacher wrote:
> On Mon, 2008-03-10 at 14:59 -0700, Dave Newton wrote:
>> --- "Kelly.Graus" <> wrote:
>> > Is it possible to specify more than one SUCCESS result for an action? 
>> For
>> > example, when the user runs an action, it could prompt them to download
>> a
>> > file (using the stream result type), and then redirect them to another
>> > page?
>> Names should be unique to a single result, otherwise there'd be no (easy)
>> way
>> to distinguish them. Depending on how you actually want the above
>> scenario to
>> work there are probably a few other options.
>> Dave
> Probably the most common practice would be to have your "success" result
> contain a meta-refresh that redirects to the action which will spit out
> your file (by stream result). If the file download requires some
> precondition to be met, then you'll probably have to set a flag in the
> user's session, since the meta-refresh will generate a whole new
> request. The advantage of this scenario is that your user will not end
> up looking at a blank page, or his/her previously filled out form (and
> potentially submitting more than once).
> -Wes
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:
Hi Wes,

I tried implementing this using a meta-refresh.  It kind of worked, but it
had some problems.  I'm simplifying the solution I came up with so I can
concentrate on getting the file downloading part working.  If you have any
hints on this, I would appreciate it.

Currently I have a jsp page that creates links to a DownloadLesson action,
and passes in a couple of parameters that describe what needs to be
downloaded.  The DownloadLesson action looks like this:

<action name="DownloadLesson"
	<result type="stream">

Here are the important parts of the DownloadLessonAction:

public class DownloadLessonAction extends ActionSupport implements
		SessionAware, ServletContextAware {
	public String execute() {
		//Look up the lesson in the current download key.
		DownloadKey downloadKey = (DownloadKey)getSession().get( "downloadKey" );
		if( downloadKey != null ) {
			//Get the lesson using the lesson identifier and version.
			Lesson lesson = downloadKey.getLesson( getLessonIdentifier(), new
Version( getVersion() ) );
			if( lesson != null ) {
				this.lesson = lesson;
				return SUCCESS;
		return ERROR;
	public getInputStream() {		
		if( lesson != null ) { inputStream = servletContext.getResourceAsStream(
lesson.getFilePath() );
			try {
				length = inputStream.available();
			} catch( e ) {}
			return inputStream;
		return null;
	public String getContentDisposition() {		
		String filename = lesson.getFilePath().substring(
lesson.getFilePath().lastIndexOf( "/" ) + 1 );
		return "attachement;filename=" + filename;
	public String getContentLength() {
		return new Integer( length ).toString();

The above is kind of working.  I click on the download link, and the Save
dialog pops up, giving me the option to Open or Save the file.  As soon as I
select the Save button, 4 exceptions get thrown.  The first is Connection reset by peer: socket write error.  The
other 3 are Software caused connection abort:
socket write error.

However, the file does get downloaded, so I'm wondering if I'm getting these
exceptions because I have debugging turned on.  So I guess my question is,
am I doing anything incorrect in how I'm accessing the file resource, and
how I'm returning the InputStream.

Once I figure out why I'm getting these exceptions, then I will go back to
trying to use the meta refresh to move to a different page.


View this message in context:
Sent from the Struts - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message