struts2文件上傳進度條
① 關於struts2框架的文件上傳問題。。。上傳的文件超過2MB就報下面的異常,請問怎麼解決
在struts.xml中設置
<constant name="struts.multipart.maxSize" value="314572800"></constant> <!-- 允許300M -->
可以允許上傳300M的呢!我試了下,上傳了個202M的電影,竟然上傳成功了!
② struts2+jquery如何實現點擊「上傳」按鈕,實現從本機選擇圖片,然後自動上傳,類似於上傳證件的那種
Uploadify是JQuery的一個上傳插件,實現的效果非常不錯,帶進度顯示。LZ可以參考下。希望能幫到你!
③ 100分。struts2實現的圖片上傳 例子
這個就是struts2的,我艹
-------------已在linux服務上線---------------------
private File userfile;
	private String userfileContentType;
	private String userfileFileName;
//get set 略
public void uploadImg() throws Exception {
		Person person = factory.getUserServiceImpl().getCurrentPerson();//得到當前用戶
		HttpServletResponse response = ServletActionContext.getResponse();
		HttpServletRequest request = ServletActionContext.getRequest();
		Calendar cal = Calendar.getInstance();
		int yy = cal.get(Calendar.YEAR);
		String savePath = request.getSession().getServletContext().getRealPath("/")+"/upload/images/"+yy+"/";
		String filePath = savePath ;
		File dir = new File(filePath);
		if (!dir.exists()) {
			dir.mkdirs();
		}
		String fileName = userfileFileName;
		String basePath = "upload/images/"+yy+"/";
		String uuid = UUID.randomUUID().toString();
		String fileType=fileName.substring(fileName.length()-3);
		File uploadedFile = new File(filePath + uuid+"."+fileType);
		//userfile.write(uploadedFile);
		InputStream in = null;  
        OutputStream out = null;  
        try {  
            in = new BufferedInputStream(new FileInputStream(userfile), 1024*1024*10);  
            out = new BufferedOutputStream(new FileOutputStream(uploadedFile),  
            		1024*1024*10);  
            byte[] buffer = new byte[1024*1024*10];  
            int len = 0;  
            while ((len = in.read(buffer)) > 0) {  
                out.write(buffer, 0, len);  
            }  
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {  
            if (null != in) {  
                try {  
                    in.close();  
                } catch (IOException e) {  
                }  
            }  
            if (null != out) {  
                try {  
                    out.close();  
                } catch (IOException e) {  
                    e.printStackTrace();  
                }  
            }  
        } 
response.setContentType("text/html;charaset=utf-8");
		response.getWriter().write("{success:'true',fileURL:'"+basePath + uuid+"."+fileType + "'}");
	}
④ jquery 進度條 struts2
請按照標準的W3C書寫
⑤ struts2中在action中怎麼對文件上傳進行處理
InputStream is = null;
   OutputStream ops = null;
   for (int i = 0; i < file.size(); i++) {
    try {
     TFile tfile = new TFile();
     if (file.get(i) == null) {
      continue;
     }
     is = new FileInputStream(file.get(i));
     //路徑
     String root = ServletActionContext.getRequest()
       .getRealPath("/uploads");
     // 根據系統時間取名字
     int pos = this.getFileFileName().get(i).lastIndexOf(".");
     String ext = this.getFileFileName().get(i).substring(pos);
     // 獲得系統時間,產生文件名
     long now = System.currentTimeMillis();
     String nowtime = String.valueOf(now);
     File destFile = new File(root + "/", nowtime + ext);
     ops = new FileOutputStream(destFile);
     byte[] b = new byte[400];
     int length = 0;
     while ((length = is.read(b)) > 0) {
      ops.write(b, 0, length);
      // ops.write(b); 這樣子同樣可行
     }
     tfile.setFileName(getFileFileName().get(i));
     tfile.setFilePath("/uploads/" + nowtime + ext);
     tfile.setFileCreatetime(currentDate);
     tfile.setFileDataid(uptdt.getDataId());
     fileservice.saveFile(tfile);// 保存上傳文件信息
    } catch (Exception ex) {
     ex.printStackTrace();
    } finally {
     is.close();
     ops.close();
    }
   }
⑥ Struts2進行文件的上傳下載,上傳已經成功了,但是文件下載時出現了問題,下載的文件是action代碼。
${downloadFileName}
要和action中的屬性相同
⑦ 求一java進度條的實現,struts2的,最好是能拿來馬上用的,謝了
明確的告訴你,沒有,WEB程序是無狀態連接的,不能獲取的進度,現在看到的那些進度條都是通用JS寫的。
⑧ struts2 如何實現上傳整個文件夾的功能
一、壓縮文件其實是可以0壓縮率直接打包,這樣其實蠻快的
二、看到網上說Applet可以上傳文件夾,具體遠離不清楚,你可以看看
三、最笨的方法,用Ajax做一個遞歸遍歷文件夾的函數,如果是文件就上傳上去,如果是文件夾就請求後台新建文件夾
四、用JSON格式把目錄和文件封裝起來,統一傳到後台,但是後台處理要比較麻煩
⑨ struts2中文件上傳問題
你要學會用debug模式來調試自己的代碼。把斷點設置在 String root = ServletActionContext.getRequest().getRealPath("/upload");  可以一步步查看每個變數和屬性的值 ,這樣更容易找到問題。
這里你需要查看root 和 destfile的值 這樣很容易看出你得到的路徑是否為你想要設置的路勁。
也可以用system.out.println(root) 列印到控制台看一下。
