我不想通过 外部组件实现文件的上传下载,struts本身可以实现吗?可以用 文件流吗?能给些具体的源代码吗,我正在做毕业设计,希望能得到指点谢谢了。

解决方案 »

  1.   

    Struts2上传是靠FromFile对象实现的。实现代码如下:
    jsp文件中FROM表单内容
    <form name="form1" action="fileUploadAction.do" method="post" enctype="multipart/form-data">
      标题:<input type="text" name="title"><br>
      文件:  <input type="file" name="myfile"><br>
         <button type="submit">上传</button>
        </form>ActionFrom文件fileFrom内容 private FormFile myfile;
    private String title;
    public FormFile getMyfile() {
    return myfile;
    }
    public void setMyfile(FormFile myfile) {
    this.myfile = myfile;
    }
    public String getTitle() {
    return title;
    }
    public void setTitle(String title) {
    this.title = title;
    }

    action execute方法内容:
    MyfileForm fu=(MyfileForm)form;

    FormFile myfile=fu.getMyfile();
    // request.setCharacterEncoding("gb2312");
    String filename=myfile.getFileName();
    String title=fu.getTitle();
    title=new String(title.getBytes("utf-8"),"GBk");

    request.setAttribute("t",title);
    request.setAttribute("f",filename);
             FileOutputStream fs=new FileOutputStream("c:\\"+myfile.getFileName());
        fs.write(myfile.getFileData());
        fs.flush();
        fs.close();
    这个就是一个简单的文件上传系统了。。你最好是找些书籍学习下。。
      

  2.   

    struts 这方面的内容在百度或者谷歌上有很多的,可以搜索一下。