首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

struts下传文件注意事项

2012-09-23 
struts上传文件注意事项1.导入两个包:commons-fileupload-1.1.1.jar和commons-io-1.1.jar 2.ActionForm类

struts上传文件注意事项
1.导入两个包:commons-fileupload-1.1.1.jar和commons-io-1.1.jar
2.ActionForm类要有FormFile类型的属性
3.JSP页面的form需要有enctype="multipart/form-data"属性,并且必需是strut标签
4.Action类里获取服务器地址例子如下:

DocAddForm d_form = (DocAddForm) form; if (d_form != null) {    FormFile file = (FormFile) d_form.getFile();    try {       byte[] content1 = file.getFileData();       String path = request.getSession().getServletContext().getRealPath("");// 获取web服务器地址        File file1 = new File(path + "/files/" + file.getFileName());       FileOutputStream out = new FileOutputStream(file1);       out.write(content1);       out.close();    } catch (Exception e) {       e.getStackTrace();    } }

热点排行