文件下载问题,请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.print