Hello Dave,

I guess the link you sent is pointing to a similar way of doing it as I did. 
This 
is my reference: 
http://sheetalshundori.blogspot.com/2008/02/struts2-dynamic-file-download.html

The reason why I am doing like this is because I don't want it to be possible 
to 
download the file without entering some kind of "ordernumber". I.e. the file 
must be
protected. The reason why I chosed this solution is simply because that is the 
solution
I found while googleing. 

Is there perhaps a better way of doing this? 

Regards,
Niklas

----------------------------------------
> Date: Sun, 3 May 2009 12:51:57 -0400
> From: newton.d...@yahoo.com
> To: user@struts.apache.org
> Subject: Re: Download a Java ME application to mobile using StreamResult
>
> Using the "stream" result is the canonical way to download files in S2.
>
> It's not clear to me what you're trying to do with the
> DownloadInterceptor class, which looks like an interceptor, but extends
> a result. In most circumstances there should be no need to create an
> interceptor for downloading files.
>
> Maybe the "stream" result docs will help. IIRC there's also a download
> example in showcase (could be wrong about that).
>
> http://struts.apache.org/2.x/docs/stream-result.html
>
> Dave
>
> Niklas Johansson wrote:
>> Hello,
>>
>> I am trying to create an application for the mobile phone from which you can 
>> download a Java ME application.
>>
>> I have gotten so far that I can download the .jad file but the only thing 
>> that happens is that the content it is presented on the screen like this:
>> MIDlet-1: WLListenerMIDlet,,WLListenerMIDlet
>> MIDlet-Jar-Size: 44641
>> MIDlet-Jar-URL: MobileTrainer.jar
>> MIDlet-Name: MobileTrainer
>> MIDlet-Vendor: Vendor
>> MIDlet-Version: 1.0
>> MicroEdition-Configuration: CLDC-1.1
>> MicroEdition-Profile: MIDP-2.1
>>
>> I.e, the actual application (.jar) is not downloaded.
>>
>> The URL when this is presented is ending with 
>> "downloadMobileTrainer.action", i.e. not the actual file. When accessing the 
>> .jad file directly it works.
>>
>> I am in a need of help because I am stuck and are getting no further. I also 
>> wonder if this is the correct way of doing it, if it is possible at all
>> using StreamResult for my purpose. I would really like to use Struts2 built 
>> in feature for this if possible.
>>
>> Here is my code:
>>
>> My download form in the jsp page:
>>
>>
>>
>>
>>
>>
>>
>> struts.xml:
>>
>>
>>
>>
>>
>>
>>
>>
>> text/vnd.sun.j2me.app-descriptor
>> ../../jsp/mobile/error.jsp
>>
>>
>>
>>
>>
>>
>>
>> Extended StreamResult class:
>>
>> public class DownloadInterceptor extends StreamResult{
>>
>> protected void doExecute(String finalLocation, ActionInvocation invocation)
>> throws Exception {
>>
>> String downloadedFileName = "MobileTraining.jad";
>>
>> contentDisposition = "filename=\"MobileTraining.jad";
>> contentLength = ""+ invocation.getStack().findValue(conditionalParse("size", 
>> invocation));
>>
>> // contentType = "text/vnd.sun.j2me.app-descriptor";
>>
>> super.doExecute(finalLocation, invocation);
>>
>> }
>> }
>>
>> My action class:
>>
>>
>> public class DownloadMTAction extends ActionSupport {
>>
>> private File mobileTrainer;
>> private String contentType;
>> private String filename;
>>
>> private InputStream inputStream;
>>
>> public InputStream getInputStream()
>> {
>> try{
>> inputStream = new FileInputStream(new 
>> File("C:\\\\Users\\Niklas\\Documents\\JavaMESDKProjects\\MobileTrainer\\dist\\MobileTrainer.jad"));
>> }catch(Exception e){
>> System.out.println("Error in DownladMTAction " + e.getMessage());
>> e.printStackTrace();
>> }return inputStream;
>> }
>>
>> public void setInputStream(InputStream inputStream){
>> this.inputStream = inputStream;
>> }
>>
>> public void setMobileTrainer(File mobileTrainer) {
>> this.mobileTrainer = mobileTrainer;
>> }
>>
>> public void setMobileTrainerContentType(String contentType) {
>> this.contentType = contentType;
>> }
>>
>> public void setMobileTrainerFileName(String filename) {
>> this.filename = filename;
>> }
>>
>> public String execute() {
>>
>> this.inputStream = getInputStream();
>>
>> if(inputStream !=null)
>> {
>>
>> return Action.SUCCESS;
>>
>> }
>> else
>> {
>> return Action.ERROR;
>> }
>> }
>> }
>>
>> I have tried to set the content-type in both my struts.xml file and the 
>> extended StreamResult class above (now commented out there).
>>
>> Thank you in advance!
>>
>> Regards,
>> Niklas
>>
>>
>>
>> _________________________________________________________________
>> Invite your mail contacts to join your friends list with Windows Live 
>> Spaces. It's easy!
>> http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>> For additional commands, e-mail: user-h...@struts.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>

_________________________________________________________________
Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.

http://www.microsoft.com/windows/windowslive/products/photos.aspx
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to