最近在维护,需要修改一个功能,先看代码:public class DownloadFileAction extends DownloadAction { private static String contentType = "application/file"; @SuppressWarnings("unchecked")
@Override
protected StreamInfo getStreamInfo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception { // 下载的文件名
SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
String FileName = sDateFormat.format(new java.util.Date()) + ".data"; // 下载方式
response.addHeader("Content-Disposition", "attachment; filename="
+ FileName); // WEBSERVICE取得数据
DownloadFileBiz sa = new DownloadFileBiz();
String hex = "";
try {
                        // 接受获得的数据
hex = sa.getFileInfo(inUseList, version);
return new ByteStreamInfo(CommonWebUtil.hexStr2bytes(hex),
contentType);
} catch (StationBizException e) {
                        // 当BIZ有异常的时候跳转错误页面
StationException se = new StationException(e);
se.setActionForward(mapping
.findForward(StationWebConst.FORWARD_ERROR));
throw se;

}
现在是有异常并且进入了catch ,但是现在最终的效果是弹出一个下载框,将错误页面的HTML内容给下载下来了,这个应该怎么处理呢。

解决方案 »

  1.   

    你可以response.getWrite().write()一些东西,比如错误信息。
    不知你想要什么效果。如果异常了你想怎么办
      

  2.   


                hex = sa.getFileInfo(inUseList, version);
                StreamInfo si = new ByteStreamInfo(CommonWebUtil.hexStr2bytes(hex),
                        contentType);
                response.addHeader("Content-Disposition", "attachment; filename="
                    + FileName);            return si;
    试试。
      

  3.   

    // 下载方式
            response.addHeader("Content-Disposition", "attachment; filename="
                    + FileName);
    放到try里面,return前面