今天下了个类下载CSV文件的..但用弹出的对话框保存可以..但用迅雷保存后缀名就变成.do的了..不是.csv文件了..大家帮个忙..看看..代码如下: public ActionForward downloadCSVFile(ActionMapping mapping, 
ActionForm form, HttpServletRequest request, 
HttpServletResponse response) { 
String method = "downloadCSVFile"; 
String userId = (String) request.getSession().getAttribute("Portal"); PrintWriter pw = null; 
response.setContentType("application/octet-stream;charset=GBK"); 
response.setHeader("Content-Disposition", 
"attachment; filename=\"mealordering.csv\""); 
List allOrderHistoryList = new LinkedList(); String strHead = Constant.RESTAURANT_NAME + "," + Constant.MEAL_NAME 
+ "," + Constant.MEAL_PRICE + "," + Constant.NUM + "," 
+ Constant.SUBSCRIBER_NAME + "," + Constant.ORDER_TIME; try { 
pw = response.getWriter(); 
pw.println(strHead); allOrderHistoryList = (List)request.getSession().getAttribute("addOrderHistory_list"); if (allOrderHistoryList == null  ¦ ¦ allOrderHistoryList.size()  <= 0) { this.debug("'", method, Constant.MESSAGE_QUERY_NOELEMENT); } else { for (Iterator iterator = allOrderHistoryList.iterator(); iterator 
.hasNext();) { 
OrderHistory orderHistory = (OrderHistory) iterator.next(); 
String restName = String.valueOf(orderHistory.getMeal() 
.getRestaurant().getRestName()); 
String mealName = String.valueOf(orderHistory.getMeal() 
.getMealName()); 
String mealPrice = String.valueOf(orderHistory.getMeal() 
.getSinglePrice()); 
String num = String.valueOf(orderHistory.getNum()); 
String subscriber = String.valueOf(orderHistory 
.getEmployee().getFullName()); 
String orderTime = String.valueOf(orderHistory.getTime()); String strLine = "\"" + restName + "\",\"" + mealName 
+ "\",\"" + mealPrice + "\",\"" + num + "\",\"" 
+ subscriber + "\",\"" + orderTime + "\""; pw.println(strLine); 

pw.flush(); 
pw.close(); 

} catch (IOException e) { 
e.printStackTrace(); 
this.debug(userId, method, "IOException"); 

return null; 

 

解决方案 »

  1.   

    response.setContentType("application/octet-stream;charset=GBK");  
    =>
    response.setContentType("application/ms-excel");  
      

  2.   

    java2000_net(5070620) 15:42:25
    ..但用迅雷保存后缀名就变成.do的了..不是.csv文件了??
    java2000_net(5070620) 15:42:35
    晕,是迅雷的一个BUG吧!哈哈哈!
      

  3.   

    你把迅雷下载后的文件,改后缀为 .csv 看看!如果能用,确认是 BUG