t.getContentType(); out.println("
上传的数据类型不是 multipart/form-data
"); } }catch(Exception ex){ throw new ServletException(ex.getMessage()); } %>
最好采用 servlet 的方式来处理以上 jsp 内的内容。 补充,只要是上网找的,一般没
问题,只不过靠 jsp 来处理 smartupload 的可能会失效。 我去网上给你找了一个。你自己看看。
response.setContentType("text/html;charset=gb2312"); PrintWriter out = response.getWriter(); SmartUpload SmartUpload(); String currentDirectoryPath=null; String savePath="E:/public_html/java_root/NETDISK/WebRoo t/
NET_SPACE/1/我的音乐/"; mySmartUpload = new
//mySmartUpload.setDenyPhysicalPath(true); mySmartUpload.setForcePhysicalPath(true);
mySmartUpload.initialize(this.getServletConfig(), request,response); // 设定上传限制 // 1.限制每个上传文件的最大长度。10M
mySmartUpload.setMaxFileSize(10000000);
// 2.限制总上传数据的长度。
// mySmartUpload.setTotalMaxFileSize(20000);
// 3.设定允许上传的文件(通过扩展名限 制),仅允许 doc,txt 文件。
// mySmartUpload.setAllowedFilesList("doc,txt");
// 4.设定禁止上传的文件(通过扩展名限 制),禁止上传带有 exe,bat, jsp,htm,html 扩展名的文件 和没有扩展名的文件。
// mySmartUpload.setDeniedFilesList("exe,bat,jsp,htm,htm l,,"); // Deny physical path
try { mySmartUpload.upload(); } catch (SmartUploadException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }
//读取其它数据
com.jspsmart.upload.Request mySmartUpload.getRequest();
req
=
String title = req.getParameter("dest");
//保存文件 for (int i = 0; i <
mySmartUpload.getFiles().getCount(); i++) {
com.jspsmart.upload.File mySmartUpload.getFiles().getFile(i);
file
=
if (file.isMissing()) continue; try { file.saveAs(savePath+file.getFileName()); } catch (SmartUploadException e) { // TODO Auto-generated catch block e.printStackTrace(); logger.info("e:"+e); }
} out.println("dest:"+title); out.close();