struts2 - Download file pfrom portal using JSR 286, Struts 2.2.0 + PortletPlugin 2.2.0 on IBM WP 6.1.5 -


i'm using jsr-286 + struts 2.2.0 + portletplugin 2.2.0

i can't set name file user wants download. user can file, it's name corrupted. instead of "myimage.png" user gets "241883e9" or "241563a2". if users renames downloaded file , opens can see file not corrupted. please, see code:

file-listing.jsp:

<li onclick="gotoaction('<s:url action="downloadattachement" portleturltype="resource" />', {'attachementid':<s:property value="id" />}, 'post')"><s:property value="name"/></li> 

function "gotoaction" dynamically generates , submits (i've tried both: post , get, doesn't help.):

<form action="/wps/myportal/!very_long_portal_url_goes_here/" method="post" id="actionurltemporaryform1295987206509"> <input type="hidden" name="attachementid" value="2" /> </form> 

my struts xml config file:

<!-- download attached file attachementid -->     <action name="downloadattachement" class="ru.portal.downloadattachementaction">         <result name="success" type="stream">             <param name="allowcaching">false</param>             <param name="contenttype">${contenttype}</param>             <param name="inputname">attachementcontents</param>             <param name="contentdisposition">>attachment;filename="${filename}"</param>             <param name="buffersize">1024</param>         </result>     </action> 

and action code:

@override     protected string bareexecute() throws exception {         string result = action.success;              attachement attachement = ejbutil.lookup(iattachementmanager.class).get(attachementid);         log.info("trying download attachement[{}]", attachement);         file attachementfile = new file(attachement.getpath());              if(attachementfile.exists()){             attachementcontents = new fileinputstream(attachementfile);         }else{             log.error("there no attachement[{}] file here[{}]",attachementid, attachement.getpath());         }           return result;     }      public string getcontenttype(){         return attachement.getmimetype();     }      public string getfilename(){         log.trace("#getfilename {}", attachement.getname());         return attachement.getname();     }      public integer getattachementid() {         return attachementid;     }      public void setattachementid(integer attachementid) {         this.attachementid = attachementid;     }      public attachement getattachement() {         return attachement;     }      public inputstream getattachementcontents() {         return attachementcontents;     }      @override     public string getcurrentactionname() {               return "downloadattachement";     } 

i've never seen log line in log file: log.trace("#getfilename {}", attachement.getname());

but see

[25.01.11 23:26:46:582 msk] 00000052 srt w com.ibm.ws.webcontainer.srt.srtservletresponse setheader warning: cannot set header. resp onse committed.

seems can't set headers response... :(

what do wrong? please help.

upd: i've found partial solution: i've added code action:

portletactioncontext.getresponse().setproperty("content-disposition", "attachment;filename=\""+attachement.getname()+"\"");                      portletactioncontext.getresponse().setproperty("content-type", attachement.getmimetype()); 

the problem in file name now: if contains non ascii char file name corrupted. file names like: "my file.doc", "02.png" work fine.

the problem in result type="stream" , in filename attribute value of "content-disposition" header. ff i've used iso-8859-1, ie6-8 i've used url-encoding. i've used user-agent header determine browser. solution has 1 issue, me it's acceptabe: ie8 replaces whitespaces in file names underscores. example "my fav image.png" "my_fav_image.png" ie8. ff undestand default encoding http , doesn't try corrupt filename attribute value. can find additional info here, on stackoverflow.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -