[Seasar-user:2600] Re: S2JSFでのファイルダウンロード

fang mingxiang fangmingxiang
2005年 9月 22日 (木) 18:19:43 JST


方です。

皆さんのご返事ありがとうございました。

解決しました。
原因はContentTypeを間違って設定してしまった。

>補足:
>
>開発環境:
> ・MyFaces1.1
> ・TOMCAT5
>シナリオ:
> 画面表示用のBeanにファイルデータがUploadedFileオブジェクトとして保持して
い
>ます。
> 画面上にファイル名をクリックしてファイルダウンロードする処理です。
>画面処理:
>      <a  m:action="#{xxxxAction.downloadFile}">
>        <span m:value="#{bean.tenpuFileName}">添付ファイル名</span>
>        <span m:inject="f:param" m:name="fileData"
>m:value="#{bean.tenpuFileData}"/>
>      </a>
>
>下記のメソッドを実行して何にも(エラーも)起こさなかったで終了しました。
>
> >
> > > S2JSFを使用していてファイルダウンロード機能を実現するために
> > > ボタンのアクションクラスに下記のメッソドを実装し、実行して正常終了する
よ
>うで
> > > すが、
> > > ファイルダウンロードのダイアログも出ないのに終了しました。
> > > なにか分かる方がいらっしゃいましたらご教授願います。
> >→終了したというのは、エラーか何か起こったのでしょうか?
> > もう少し詳細な情報があると解決につながりやすいと思います。
> >
> > また response オブジェクトを取得する際には
> > response オブジェクトの setter を用意すればOKです。
> > http://www.seasar.org/DIContainer.html#Request
> > こちらを参考になさってください。
> >
> >
> > > public String downloadFile() {
> > >
> > > // TODO 自動生成されたメソッド・スタブ
> > > ExternalContext context =
> > > FacesContext.getCurrentInstance().getExternalContext();
> > > HttpServletResponse response = (HttpServletResponse)
> > > context.getResponse();
> > > response.setContentType("any mime type");
> > > try {
> > > ServletOutputStream out = response.getOutputStream();
> > > out.write(fileData.getBytes());
> > > out.flush();
> > > out.close();
> > > FacesContext.getCurrentInstance().responseComplete();
> > > }
> > > catch (IOException ex) {
> > > ex.printStackTrace();
> > > }
> > > return "success";
> > > }





Seasar-user メーリングリストの案内