You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Kelly.Graus" <Ke...@toltech.net> on 2008/03/10 22:51:25 UTC

[S2] Multiple SUCCESS results?

Hello,

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?

Thanks!

Kelly
-- 
View this message in context: http://www.nabble.com/-S2--Multiple-SUCCESS-results--tp15959652p15959652.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: [S2] Multiple SUCCESS results?

Posted by "Kelly.Graus" <Ke...@toltech.net>.

Wes Wannemacher wrote:
> 
> 
> On Mon, 2008-03-10 at 14:59 -0700, Dave Newton wrote:
>> --- "Kelly.Graus" <Ke...@toltech.net> 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: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
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"
class="net.toltech.lessondownloader.webapp.action.DownloadLessonAction">
	<result type="stream">
		application/octet-stream
		${contentDisposition}
		${contentLength}
	</result>
</action>	


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 java.io.InputStream getInputStream() {		
		if( lesson != null ) {
			java.io.InputStream inputStream = servletContext.getResourceAsStream(
lesson.getFilePath() );
			
			try {
				length = inputStream.available();
			} catch( java.io.IOException 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
java.net.SocketException: Connection reset by peer: socket write error.  The
other 3 are java.net.SocketException: 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.

Thanks!

Kelly
-- 
View this message in context: http://www.nabble.com/-S2--Multiple-SUCCESS-results--tp15959652p16012550.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: [S2] Multiple SUCCESS results?

Posted by Wes Wannemacher <we...@wantii.com>.
On Mon, 2008-03-10 at 14:59 -0700, Dave Newton wrote:
> --- "Kelly.Graus" <Ke...@toltech.net> 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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] Multiple SUCCESS results?

Posted by Dave Newton <ne...@yahoo.com>.
--- "Kelly.Graus" <Ke...@toltech.net> 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


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