servlet文件下载和jspsmartupload上传
SmartUpload smart = new SmartUpload(); org.lxh.smart.Request re = smart.getRequest(); smart.initialize(pageContext); smart.upload(); String ext = smart.getFiles().getFile(0).getFileExt(); Time time = new Time(request.getRemoteAddr()); //Time time = new Time("127.0.0.1"); String fileName = time.getIPTimeRand() + "." + "docx"; String path = getServletContext().getRealPath("/")+"teacher" + java.io.File.separator + fileName; smart.getFiles().getFile(0).saveAs(path);
String path = request.getParameter("path"); String name = request.getParameter("name"); File f = new File(path); if(f.exists()){ FileInputStream fis = new FileInputStream(f); byte[] b = new byte[fis.available()]; fis.read(b); response.setCharacterEncoding("gbk"); response.setHeader("Content-Disposition","attachment; filename="+name+".docx"); //获取响应报文输出流对象 ServletOutputStream out =response.getOutputStream(); //输出 out.write(b); out.flush(); out.close(); }