网站大量收购独家精品文档,联系QQ:2885784924

JSP程序设计案例教程《Java Web程序设计》_项目库_单元案例_文件上传下载及发送邮件教学案例.doc

JSP程序设计案例教程《Java Web程序设计》_项目库_单元案例_文件上传下载及发送邮件教学案例.doc

  1. 1、本文档共11页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
JSP程序设计案例教程《Java Web程序设计》_项目库_单元案例_文件上传下载及发送邮件教学案例

Unit16- 文件上传下载及发送邮件 课堂案例1—应用jspSmartUpload组件jspSmartUpload组件jspSmartUpload组件jspSmartUpload组件jspSmartUpload组件jspSmartUpload组件chap08\WEB-INF\classes文件夹中。 3.编写上传文件的HTML页面upload.html。 【程序代码】upload.html 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 html head title文件上传/title http-equiv=content-type content=text/html; charset=gb2312 /head body p align=center上传产品附加信息/p form method=post action=do_upload.jsp enctype=multipart/form-data table width=90% border=1 align=center tr tddiv align=center产品图片: input type=file name=file1 size=30 /div/td /tr tr tddiv align=center产品说明: input type=file name=file2 size=30 /div/td /tr tddiv align=center input type=submit name=submit value=上传 /div/td /tr /table /form /body /html 【程序说明】 第8行:创建上传表单,指定以post方式进行提交,由do_upload.jsp负责处理,同时指定enctype属性为multipart/form-data; 第9行—第24行:以表格形式显示信息。 4.编写处理上传文件操作的JSP文件do_upload.jsp。 【程序代码】do_upload.jsp 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 %@ page contentType=text/html;charset=GBK import=java.util.*,com.jspsmart.upload.* errorPage= % html head title文件上传处理页面/title meta http-equiv=Content-Type content=text/html; charset=gb2312 /head body % SmartUpload su=new SmartUpload(); su.initialize(pageContext); // su.setMaxFileSize(10000); // su.setTotalMaxFileSize(20000); // su.setAllowedFilesList(doc,txt); // su.setDeniedFilesList(exe,bat,jsp,htm,html,,); su.upload(); int count = su.save(/upload, su.SAVE_VIRTUAL); out.println(count+个文件上传成功!br); for (int i=0;isu.getFiles().getCount();i++) { com.jspsmart.upload.File file = su.getFiles().getFile(i); if (file.isMissing()) continue; out.println(br文件名: + file.getFileName()+ 长度:+file.getSize()); } % /body /html 【程序说明】 第1行:设置页面属性,包括JSP页面类型和字符编码SmartUpload新建上传对象su; 第10行:使用initialize方法进行上传初始化操作; 第11行—第14行:设定上传限制; 第11行:限制每个上传文件的最大长度(可选); 第12行:限制总上传数据的长度(可选); 第13行:通过扩展名限制设定允许上传的文件,这里仅允许doc,txt文件(可选); 第14行:通过扩展名限制设定禁止上传的文件,禁止上传带有exe,bat,jsp,htm,html扩展名的文件和没有扩展名的文件(可选); 第15行:使用upload方法

您可能关注的文档

文档评论(0)

feixiang2017 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档