public String upload(){ HttpSession session=ActionContext.getActionContext().getMap().getSession(); String filepath=session.getServletContext().getRealPath("/")+"image/"; File f=new File(filepath); if(!f.exists()){ f.mkdir(); } f=new File(filepath+"/"+System.currentTimeMillis()+".jpg"); try { FileInputStream fis=new FileInputStream(file); FileOutputStream fos=new FileOutputStream(f); byte [] data=new byte[1024]; while((fis.read(data, 0, 1024))!=-1){ fos.write(data, 0, 1024); } fos.flush(); fos.close(); fis.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return "add"; }
文件上传action
猜你喜欢
转载自wenkaixuan.iteye.com/blog/1399349
今日推荐
周排行