首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

文件下载有关问题,请XDJM帮忙下

2011-12-12 
文件下载问题,请XDJM帮忙下在本机下载能正常保存、打开,本地用TOMCAT在服务器上下载是直接打开页面,显示乱

文件下载问题,请XDJM帮忙下
在本机下载能正常保存、打开,本地用TOMCAT

在服务器上下载是直接打开页面,显示乱码,服务器用WEBLOGIC

是不是与TOMCAT和WEBLOGIC有关,应该怎么改呢,大家帮我看下

代码如下:

public   class   DownUploadController   implements   Controller   {

private   DataSource   dataSource;
private   ShareImpl   shareImpl;

@SuppressWarnings( "static-access ")
public   ModelAndView   handleRequest(HttpServletRequest   request,
HttpServletResponse   arg1)   throws   Exception   {
String   flag   =   "11111 ";
String   downloadid   =   CharacterSet.doNull(request.getParameter( "downloadid "));
//final   String   sysTime   =   shareImpl.getSysTime();
//构造存储文件路径
Random   random   =   new   Random();
String   tempRandomNum   =   String.valueOf(random.nextInt());
final   String   downloadUrl   =   "./mcm.upload/ "   +   tempRandomNum   +   ".doc ";
String   realPath   =   request.getSession().getServletContext().getRealPath( "/ ")   +   "mcm.upload\\ ";
shareImpl.delAllFile(realPath);
File   dirPath   =   new   File(realPath);
                if   (!dirPath.exists())   {
                        dirPath.mkdirs();
                }
//final   String   realPath   =   request.getSession().getServletContext().getRealPath(request.getPathInfo());  
final   String   tempDownload   =   realPath   +   tempRandomNum   +   ".doc ";
System.out.println( "-------------   tempDownload   =   "+tempDownload);
try{
final   JdbcTemplate   jt   =   new   JdbcTemplate(dataSource);
  //取得数据库中的数据
String   Sql= "select   *   from   cust_solution   "
      + "where   ORDID= "   +   downloadid;

jt.query(Sql,   new   RowCallbackHandler(){
public   void   processRow(ResultSet   rs)   throws   SQLException   {
//rs.next();
int   bytesum=0;
        int   byteread=0;
       
  //将数据库中的数据读到流中  
InputStream   inStream=rs.getBinaryStream( "ATTACHMENT ");  
try{
FileOutputStream   fs=new   FileOutputStream(tempDownload);

    byte[]     buffer   =new     byte[1444];
        while   ((byteread=inStream.read(buffer))!=-1)
        {
              //System.out.println( "---------   字节是   =   "+byteread);
              bytesum+=byteread;
              //System.out.println(bytesum);
              fs.write(buffer,0,byteread);
          }
}catch(Exception   e){
System.out.println(e);
}
}});
flag   =   "00000 ";
}catch(Exception   e)
{
System.out.println( "下载失败 ");


e.printStackTrace();
}
//判断跳转页面
if(flag.equals( "00000 ")){
return   new   ModelAndView(downloadUrl);     //返回操作成功页面
}else{
return   new   ModelAndView( "./share/Err.jsp ");     //返回操作失败页面
}
        }



[解决办法]
服务器上的LANG是什么啊,是不是和你本地不一样啊,字符集加个FILETER,过滤转换流

热点排行