求struts+fileupload 上传实例:最好能包括:前台页面,后台Action等的实现

解决方案 »

  1.   

    网上很多 不过我是自己写的 也很方便
    下面是DONWLOAD的ACTION
    package asatapp;import javax.servlet.ServletContext;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.actions.DownloadAction;public class CommonDownloadAction extends DownloadAction  {    protected synchronized StreamInfo getStreamInfo(ActionMapping mapping,
                                           ActionForm form,
                                           HttpServletRequest request,
                                           HttpServletResponse response)
                throws Exception {        // Download a "jpeg" file - gets the file name from the
            // Action Mapping's parameter
            String contentType         = "application/x-msdownload";
            String path        = mapping.getParameter();
            response.setHeader("Content-Disposition","attachment;  filename=\""  +  path  +  "\"");
            ServletContext application = servlet.getServletContext();        return new ResourceStreamInfo(contentType, application, path);    }}
      

  2.   

    前台用<html:file property="file"/>选择文件
    后台获得文件
    UploadFileForm uploadFileForm = null;
    if (form != null) {
    uploadFileForm = (UploadFileForm) form;
    } FormFile file = uploadFileForm.getFile();
    然后处理文件就行了
    UploadFileForm中定义一个属性FormFile file