Chinaunix首页 | 论坛 | 博客
  • 博客访问: 528296
  • 博文数量: 855
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 5005
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-16 19:08
文章分类

全部博文(855)

文章存档

2011年(1)

2008年(854)

我的朋友

分类:

2008-10-16 19:25:10

    

         

         

    

   

         

         

    

view plaincopy to clipboardprint?
    jsp中的表单

    jsp中的表单view plaincopy to clipboardprint?
   

package com.actions;

 

    import java.io.*;

 

    import org.apache.struts2.ServletActionContext;

 

    import com.opensymphony.xwork2.ActionSupport;

 

    public class FileUploadActions extends ActionSupport {

        private static final int BUFFER_SIZE=16*1024;

        private File file;

        private String contentType;

        private String fileName;

        public File getFile() {

            return file;

        }

        public void setFile(File file) {

            this.file = file;

        }

        public void setFileContentType(String contentType) {

            this.contentType = contentType;

        }

        public void setFileFileName(String fileName) {

            this.fileName = fileName;

        }

        public String execute(){

            File dstFile=new File(ServletActionContext.getServletContext().getRealPath("/upload"+"/"+fileName));

            try {

                InputStream is=new BufferedInputStream(new FileInputStream(file),BUFFER_SIZE);

                OutputStream os=new BufferedOutputStream(new FileOutputStream(dstFile),BUFFER_SIZE);

                byte[] buffer=new byte[BUFFER_SIZE];

                while(is.read(buffer)>0){

                    os.write(buffer);

                }

                is.close();

                os.close();

            } catch (Exception e) {

                // TODO Auto-generated catch block

                e.printStackTrace();

            }

            return SUCCESS;

        }

    }

   

    view plaincopy to clipboardprint?package com.actions;         import java.io.*;         import org.apache.struts2.ServletActionContext;         import com.opensymphony.xwork2.ActionSupport;         public class FileUploadActions extends ActionSupport {         private static final int BUFFER_SIZE=16*1024;         private File file;         private String contentType;         private String fileName;         public File getFile() {             return file;         }         public void setFile(File file) {             this.file = file;         }         public void setFileContentType(String contentType) {             this.contentType = contentType;         }         public void setFileFileName(String fileName) {             this.fileName = fileName;         }         public String execute(){             File dstFile=new File(ServletActionContext.getServletContext().getRealPath("/upload"+"/"+fileName));             try {                 InputStream is=new BufferedInputStream(new FileInputStream(file),BUFFER_SIZE);                 OutputStream os=new BufferedOutputStream(new FileOutputStream(dstFile),BUFFER_SIZE);                 byte[] buffer=new byte[BUFFER_SIZE];                 while(is.read(buffer)>0){                     os.write(buffer);                 }                 is.close();                 os.close();             } catch (Exception e) {                 // TODO Auto-generated catch block                 e.printStackTrace();             }             return SUCCESS;         }     }  package com.actions;

 

    import java.io.*;

 

    import org.apache.struts2.ServletActionContext;

 

    import com.opensymphony.xwork2.ActionSupport;

 

    public class FileUploadActions extends ActionSupport {

     private static final int BUFFER_SIZE=16*1024;

     private File file;

     private String contentType;

     private String fileName;

     public File getFile() {

      return file;

     }

     public void setFile(File file) {

      this.file = file;

     }

     public void setFileContentType(String contentType) {

      this.contentType = contentType;

     }

     public void setFileFileName(String fileName) {

      this.fileName = fileName;

     }

     public String execute(){

      File dstFile=new File(ServletActionContext.getServletContext().getRealPath("/upload"+"/"+fileName));

      try {

       InputStream is=new BufferedInputStream(new FileInputStream(file),BUFFER_SIZE);

       OutputStream os=new BufferedOutputStream(new FileOutputStream(dstFile),BUFFER_SIZE);

       byte[] buffer=new byte[BUFFER_SIZE];

       while(is.read(buffer)>0){

        os.write(buffer);

       }

       is.close();

       os.close();

      } catch (Exception e) {

       // TODO Auto-generated catch block

       e.printStackTrace();

      }

      return SUCCESS;

     }

    }


    view plaincopy to clipboardprint?
    action代码

    action代码view plaincopy to clipboardprint?


     view plaincopy to clipboardprint?
   

           

               

                    image/bmp,image/png,image/gif,image/jpeg

               

           

           

            index.jsp

            index.jsp

       



--------------------next---------------------

阅读(197) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~