美文网首页
Struts2中上传、下载

Struts2中上传、下载

作者: 蘋果_283e | 来源:发表于2017-04-13 12:00 被阅读0次

    1、上传开发步骤

    (1)<s:form action="person_add" method="post" name="kk" enctype="multipart/form-data">

    (2)web应用中必须包含common-fileupload.jar和common-io.jar

    (3)(package上面写)

    <!-- 上传文件大小限制设置 -->

    <constant name="struts.multipart.maxSize" value="15242880" />

    <!-- 把它设置为开发模式,发布时要设置为false -->

    <constant name="struts.devMode" value="true" />

    <!-- 编码格式 -->

    <constant name="struts.i18n.encoding" value="UTF-8" />

    (4)在webroot下创建upload文件夹

    (5) 开发action(文件名:myfile filepath myfilleName)

    public String add() throws Exception {// 添加

    String filename=this.getMyfileFileName();

    filename=FileUpload2.upload(filename, myfile);//完成上传

    System.out.println("文件名:"+filename);

    per.setFilepath(filename);//设置路径

    ps.add(per);//把对象添加进数据库

    return "tolist";

    }

    public String download() throws Exception{//下载

    HttpServletRequest request = ServletActionContext.getRequest();

    HttpServletResponse response = ServletActionContext.getResponse();

    String filepath="//upload//"+per.getFilepath();

    FileDownLoad.download(filepath, request, response);//调用工具类下载

    return null;//为空

    }

    常用三种方式

    上传就是将信息从个人计算机(本地计算机)传递到中央计算机(远程计算机)系统上,让网络上的人都能看到。将制作好的网页、文字、图片等发布到互联网上去,以便让其他人浏览、欣赏。这一过程称为上传。

    Java实现文件上传的几个组件:

    1 SmartUpload 用的最多的一个组件,已经不再更新了,可以实现上传和下载

    2 FileUpload Apache实现的文件上传组件,功能齐备

    3 J2KUpload java2000实现的文件上传组件,全部使用内存,适合多个不超过10M的小文件

    相关文章

      网友评论

          本文标题:Struts2中上传、下载

          本文链接:https://www.haomeiwen.com/subject/mqcbattx.html