随笔-0  评论-0  文章-6  trackbacks-0

Upload.jsp:

代码
  1. < html:form   action = "UploadAction.do"   method = "POST"   enctype = "multipart/form-data" >   
  2. < table   width = "100%"   height = "100%"   border = "0"   cellpadding = "0"   cellspacing = "0" >   
  3.     < tr   bgcolor = "#C8E8F0"   id = "advertServer" >   
  4.        < td   align = "right" > 选择文件 </ td >   
  5.        < td   height = 30   bgcolor = "#F7FBFF" >   
  6.           < html:file   property = "theFile"   styleId = "theFile"   styleClass = "textbox"   size = "50"   >   
  7.        </ td >   
  8.    </ tr >   
  9. </ table >   
  10. </ html:form >   

UpLoadForm.java:
代码
  1.   
  2. public class UpLoadForm extends ValidatorForm {   
  3.   
  4.     private FormFile theFile;   
  5.   
  6.         public FormFile getTheFile() {
      return theFile;
     }
  7.  public void setTheFile(FormFile theFile) {
      this.theFile= theFile;
     }
  8. }   

UpLoadAcion.java
代码
  1. public class UpLoadAction extends BaseAction {   
  2.           
  3.   public ActionForward execute(ActionMapping mapping, ActionForm argForm,HttpServletRequest request, HttpServletResponse response) {   
  4.         UpLoadForm form = (UpLoadForm)argForm;   
  5.         FormFile uploadFile = (FormFile) form.getTheFile();   
  6.         ServletContext context = getServlet().getServletContext();   
  7.         String filePath = context.getRealPath("/");// 取当前系统路径   
  8.          stream = formFile.getInputStream();// 把文件读入   
  9.          bos = new FileOutputStream(fileName);   
  10.         int bytesRead = 0;   
  11.         byte[] buffer = new byte[8192];   
  12.         while ((bytesRead = stream.read(buffer, 08192)) != -1) {bos.write(buffer, 0, bytesRead);// 将文件写入服务器    
  13.         mapping.findForward("success");    
  14.   }   
  15. }   

posted on 2007-02-02 14:02 阿mjay 阅读(950) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: