jspSmartUpload做上传 --(附件已做特别中文处理)

来源:互联网 发布:淘宝评价管理 编辑:程序博客网 时间:2024/05/16 16:58
Jsp界面代码
注意一点 在form属性里面添加enctype="multipart/form-data"
 <form name="SCSDICOnnection" action="SCSDIConnectionProcess.jsp" method="post" ENCTYPE="multipart/form-data"> 

转交给处理界面
jsp代码
<%
Linkimport linkimport=new Linkimport();
SmartUpload mySmartUpload = new SmartUpload();
//初始化SmartUpload对象
mySmartUpload.initialize(this.getServletConfig(), request, response);
try {
 
    linkimport.LinkImport(context,mySmartUpload,request, response);
  
} catch (Exception e) {
    e.printStackTrace();
}
out.clear();   
out = pageContext.pushBody(); 
 
%> 
后台java代码
 public void LinkImport(Context context, SmartUpload mySmartUpload,
   HttpServletRequest request, HttpServletResponse response) {
  try {
   String filename = null;
   // 上传文件
   mySmartUpload.upload();
//设置上传文件格式
   mySmartUpload.setAllowedFilesList("csv,txt");
//上传到什么位置
   mySmartUpload.save(request.getSession().getServletContext()
     .getRealPath("/")
     + "scscommoncentral/download/");
   filename = mySmartUpload.getFiles().getFile(0).getFileName();
   String csvFilePath = request.getSession().getServletContext()
     .getRealPath("/")
     + "scscommoncentral/download/"
     + mySmartUpload.getFiles().getFile(0).getFileName();
   String txtFilePaht = request.getSession().getServletContext()
     .getRealPath("/")
     + "scscommoncentral/download/"
     + mySmartUpload.getFiles().getFile(1).getFileName();
   // 处理文件

   DataProcess(context, csvFilePath, txtFilePaht);//忽略
   // 文件回传
   responseUser(csvFilePath, response, filename);//忽略
  } catch (Exception e) {
   System.out.println(e);
  }
 }
0 0
原创粉丝点击