• Struts文件上传机制


    1首先建立文件上传jsp页面如下

    <form action="" method="post"  enctype="multipart/form-data" >
                  
    文件<input type="file" name="upload">
    <input type="submit" class="button" value="添加"/>
              </form>

    2.action处理上传业务

    public class fileupload(){
    private File upload;
    private
    String uploadFileName;//struts根据表单name属性自动获取上传的文件名 private String uploadContentType;//struts根据表单name属性自动获取上传的文件属性

    public File getUpload() {
    return upload;
    }
    public void setUpload(File upload) {
    this.upload = upload;
    }
    public String getUploadFileName() {
    return uploadFileName;
    }
    public void setUploadFileName(String uploadFileName) {
    this.uploadFileName = uploadFileName;
    }
    public String getUploadContentType() {
    return uploadContentType;
    }
    public void setUploadContentType(String uploadContentType) {
    this.uploadContentType = uploadContentType;

    public String Insert() throws IOException{

    String path= "D:/workspace/.metadata/.me_tcat7/webapps/EducationWebsite/upload/";//指定文件保存路径(在此保存在wbsapps文件中是为了在不进行刷新的情况下图面能及时显现到页面中)
    System.out.println(path);
    FileInputStream fis=new FileInputStream(upload);
    FileOutputStream fos=new FileOutputStream(path+uploadFileName);
    int data = 0;
    while((data=fis.read())!=-1){
    fos.write(data);
    }
    fis.close();
    fos.close();
    cou.setPicture(uploadFileName);

    }

    3.xml文件中配置上传文件的最大容量:

    <constant name="struts.multipart.maxSize" value="1024000000"/>//配置上传文件的最大值10G

  • 相关阅读:
    GRYZ20211029模拟赛解题报告
    LG 题解 CF1545B AquaMoon and Chess
    GRYZ10.27模拟赛解题报告
    开博客通告
    民科吧编程赛 题解
    民科吧编程赛 试题
    四则运算开平方——对民科吧编程大赛题目的再探究
    The First
    机械手相机9点坐标标定-基于C#+EmguCV
    Emgucv图像处理工具
  • 原文地址:https://www.cnblogs.com/feitianshaoxai/p/5715338.html
Copyright © 2020-2023  润新知