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);
注意一点 在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();
}
linkimport.LinkImport(context,mySmartUpload,request, response);
} catch (Exception e) {
e.printStackTrace();
}
out.clear();
out = pageContext.pushBody();
out = pageContext.pushBody();
%>
后台java代码
public void LinkImport(Context context, SmartUpload mySmartUpload,
HttpServletRequest request, HttpServletResponse response) {
后台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);//忽略
// 文件回传
// 上传文件
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);
}
System.out.println(e);
}
}