struts2 文件上傳Action類
public class MyFileUploadlAction extends ActionSupport { private File image;// 獲取上傳文件 private String imageFileName;// 獲取上傳文件名稱 private String imageContentType;// 獲取上傳文件類型/** * */ private static final long serialVersionUID = 1L; public String fileUpload() { if (image == null) { return "jsp"; } File savefile = new File ("D:\\upload" + "/" + imageFileName); if (!savefile.getParentFile().exists() ) { savefile.getParentFile().mkdirs(); } try { InputStream is = new BufferedInputStream (new FileInputStream (image) ); OutputStream os = new BufferedOutputStream (new FileOutputStream (savefile) ); byte[] buffer = new byte[4 * 1204]; while (is.read (buffer) > 0) { os.write (buffer); } is.close(); os.close(); } catch (IOException e) { e.printStackTrace(); } String[] t = imageContentType.split ("/");
for (String s : t) { System.out.println (s); } return "jsp"; } }</pre>
本文由用戶 cn55 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!