zoukankan      html  css  js  c++  java
  • struts2文件上传、下载、防止重复提交

    Struts2 文件上传
    Struts2 文件上传基于 Struts2 拦截器实现; Struts2 文件上传使用的是 fileupload 组件; Form 配置 enctype="multipart/form-data"; Struts2 获取上传文件:name (name 是文件表单的 name) Struts2 获取上传文件名:name+FileName; Struts2 获取上传文件的类型:name+ContentType;
    配置文件的大小及类型
    <paramname="allowedTypes">image/bmp,image/x-png,image/gif,image/jpg,image/jpeg</param> <paramname="maximumSize">81101</param>
    <s:fielderror></s:fielderror>
    大文件上传
    Struts2 文件上传大小默认是 2M;
    <constantname="struts.multipart.maxSize"value="20000000"></constant>
    多文件上传时,对应的属性变成数组,循环上传。

    Struts2文件下载
    返回的是文件流
    <result type="stream">
            <param name="contentDisposition">attachment;filename=${fileName}</param>
    </result>
    return InputStreamgetInputStream();
    示例:
        private String fileName;

        public String getFileName() throws Exception{
            fileName=new String(fileName.getBytes(),"ISO8859-1");
            return fileName;
        }

        public void setFileName(String fileName) {
            this.fileName = fileName;
        }
        
        public InputStream getInputStream()throws Exception{
            File file=new File("C:/例1.jpg");
            this.fileName="例1";
            return new FileInputStream(file);
        }

    使用<s:token/>标签防重复提交
    <s:token></s:token> :加在 form 里; 使用 token 拦截器:
             <interceptor-ref name="token"></interceptor-ref>
             <interceptor-ref name="defaultStack"></interceptor-ref>
             <result name="invalid.token">/student.jsp</result>
    在 struts.xml 里配置,假如出现重复提 交,则直接回到页面;
    <s:actionerror/>:在页面上显示错误信息;
    使用 tokenSession 拦截器防重复提交
    tokenSesssion 拦截器直接无视重复提交的请求;
        <interceptor-refname="tokenSession"></interceptor-ref>
    <interceptor-refname="defaultStack"></interceptor-ref>

  • 相关阅读:
    RSA算法
    本地CodeForces
    基于Giolite 多人开发
    DES算法
    MD5算法
    仓库库存管理系统(C+MySQL+ODBC)
    Spring源码解析(一)开篇
    JDK动态代理实现源码分析
    J.U.C Atomic(一)CAS原理
    JDK 注解详解
  • 原文地址:https://www.cnblogs.com/cyf18/p/14289452.html
Copyright © 2011-2022 走看看