私が使用しているIBM WPに2.2.0 + PortletPlugin 2.2.0 Strutsのtユーザーがダウンロードしたいファイルの名前を設定します。 ユーザーはファイルを取得できますが、名前は壊れています。 "myImage.png"の代わりに "241883e9"または "241563a2"を取得します。 ダウンロードしたファイルの名前を変更して開くと、ファイルが破損していないことがわかります。ダウンロードファイルpfromポータルは、JSR-286 + Strutsの2.2.0 + PortletPlugin 2.2.0</p> <p>私に」6.1.5
ファイルlisting.jsp: "goToActionは" 動的から生成し、それを提出
<li onclick="goToAction('<s:url action="downloadattachement" portletUrlType="resource" />', {'attachementId':<s:property value="id" />}, 'POST')"><s:property value="name"/></li>
機能(私は両方を試してみた:、私のコードを参照してくださいPOSTをし、GET、それはしていません助ける):。
<form action="/wps/myportal/!VERY_LONG_PORTAL_URL_GOES_HERE/" method="POST" id="actionUrlTemporaryForm1295987206509"> <input type="hidden" name="attachementId" value="2" /> </form>
私のストラットXML設定ファイル:
<!-- Download attached file by 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>
とアクションコード:
@Override
protected String bareExecute() throws Exception {
String result = Action.SUCCESS;
Attachement attachement = EJBUtil.lookup(IAttachementManager.class).get(attachementId);
LOG.info("Trying to download Attachement[{}]", attachement);
File attachementFile = new File(attachement.getPath());
if(attachementFile.exists()){
attachementContents = new FileInputStream(attachementFile);
}else{
LOG.error("There is 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";
}
私は私のログファイルにこのLOGラインを見たことがない: LOG.trace( "#getFileName {}"、attachement.getName());
しかし、私は
参照[25.01.11 23:46:26 582 MSK] 00000052 SRT W com.ibm.ws.webcontainer.srt.SRTServletResponseのsetHeaderの警告:ヘッダーを設定することはできません。 Resp は既にコミットされています。
は、私は:(
は私が間違って何をしますか...応答のためのヘッダーを設定することはできませんように思える助けてください
UPD:?。私は部分的な解決策見つけた: を私はしました自分の行動にこのコードを追加:
PortletActionContext.getResponse().setProperty("content-Disposition", "attachment;filename=\""+attachement.getName()+"\"");
PortletActionContext.getResponse().setProperty("content-Type", attachement.getMimeType());
問題は今、ファイル名にあります。それは非アスキー文字のファイル名が破損している含まれている場合のような ファイル名:「私のfile.docのは」、「02.png」うまく動作します。