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

本文详细介绍了在JSP界面中实现文件上传功能的过程,并通过SmartUpload类进行文件的处理和保存,包括允许的文件类型、上传路径以及后续的数据处理与文件回传。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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);
  }
 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值