解决从tomcat移植到weblogic的两个问题

解决从tomcat移植到weblogic的两个问题 1. 用XmlHttp获取xml,responseXml为空。 解决方法: 在web.xml中加入 xml text/xml xsl text/xml 2. 用SmartUpload下载文件时出错 出错信息: java.io.IOException: 文件名、目录名或卷标语法不正确。 at java.io.WinNTFileSystem.canonicalize0(Native Method) at java.io.Win32FileSystem.canonicalize(Win32FileSystem.java:395) at java.io.File.getCanonicalPath(File.java:531) at weblogic.servlet.internal.WebAppServletContext.getRealPath (WebAppServletContext.java:666) at com.jspsmart.upload.SmartUpload.isVirtual(SmartUpload.java:1180) Truncated. see log file for complete stacktrace 解决方法:自己写了一个Servlet来下载文件,代码如下: 1public class DownLoad extends HttpServlet 2{ 3 private static final long serialVersionUID = -84138329260803824L; 4 public void init() throws ServletException 5 { 6 } 7 8 public void doGet(HttpServletRequest request, HttpServletResponse response) 9 throws ServletException, IOException 10 { 11 OutputStream os = null; 12 FileInputStream fis = null; 13 try 14 { 15 String fileName = request.getParameter("filename"); //要下载的文件,包括路径 16 String downFileName = fileName.substring(fileName.lastIndexOf("\\") + 1); //去掉路径 17 18 os = response.getOutputStream(); 19 File f = new File(fileName); 20 21 response.setHeader("Content-type:", "application/octet-stream"); 22 response.setHeader("Accept-Ranges:", "bytes"); 23 response.setHeader("Accept-Length:", Long.toString(f.length())); 24 response.setHeader("Content-Disposition", "attachment; filename=" + downFileName); 25 26 fis = new FileInputStream(f); 27 byte[] b = new byte[1024]; 28 int i = 0; 29 while((i = fis.read(b)) > 0) 30 os.write(b, 0 ,i); 31 } 32 catch (Exception e) 33 { 34 e.printStackTrace(); 35 } 36 finally 37 { 38 fis.close(); 39 os.flush(); 40 os.close(); 41 } 42 } 43 44 public void doPost(HttpServletRequest request, HttpServletResponse response) 45 throws ServletException, IOException 46 { 47 doGet(request,response); 48 } 49}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值