分享

Struts上传总结

 Sunny_Gql 2010-05-29
1: 在JSP中: 2:在Struts中: /admin/upload.jsp /error.jsp /UploadFile.jsp 20000000000000 在外添加 nstant name="struts.multipart.maxSize"value="1000000000">constant 3:在com.dota.action.UploadFileAction中: public String execute(){ String newFileName = ServletActionContext.getServletContext().getRealPath("/cs")+"/"+fileFileName; try { /*原理就是在本机内读,在服务器上写入在设置好的路径内*/ InputStream is = new BufferedInputStream(new FileInputStream(file)); OutputStream os = new BufferedOutputStream(new FileOutputStream(newFileName)); byte[] buff = new byte[1000]; int i = 0; while( (i=is.read(buff))>0 ){ os.write(buff, 0, i); } is.close(); os.close(); } catch (Exception e) { e.printStackTrace(); return ERROR; } if(fileFileName!=null){ this.setFf("上传成功,点击查看:"); }else{ this.setFf("上传失败"); } return SUCCESS; }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多