国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

文件上傳一

2019-11-08 18:21:20
字體:
來源:轉載
供稿:網友
 public class Upload extends ActionSupport {         PRivate File[] image ; //多個文件 ,如果單個文件 ,就定義成  File image ;    private String[] imageFileName ;//多個文件名 ,如果單個文件 ,就定義成  String imageFileName ;    private String[] imageContentType ;//多個文的內容類型,如果 單個文件就定義成 String imageContentType get(),set() ..../***其中image為jsp中的File  的name*<input type="file" name="image" /><br />*/    public String execute() throws Exception {                 String realpath = ServletActionContext.getServletContext().getRealPath("/images") ;        System.out.println("Real Path : "+ realpath );        if (image != null){            File savedir = new File(realpath) ;            if (! savedir.exists()) {                savedir.mkdirs() ;            }//            File savefile = new File(realpath, this.imageFileName ) ;            for (int i = 0; i < image.length; i++){                                 File savefile = new File(realpath, imageFileName[i]) ;                FileUtils.copyFile(image[i], savefile) ;                System.out.println(imageContentType[i]);            }                         ActionContext.getContext().put("message""上傳成功:" + realpath) ;                     }                 return SUCCESS ;    }}

方法一:

  ActionContext ctx=ActionContext.getContext();  

HttpServletRequest request=(HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);  

HttpServletResponse response=(HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);

方法二:

HttpServletRequest request=ServletActionContext.getRequest();HttpServletResponse response=ServletActionContext.getResponse();

方法三:

實現ServletRequestAware接口,并實現 

public void setServletRequest(HttpServletRequest request) ;方法

public String addLinkMan() throws IOException {                //判斷是否需要上傳文件        if(upload != null) {//上傳            //上傳邏輯            //1 在服務器文件夾里面創建文件            File serverFile = new File("I://crm"+"/"+uploadFileName);            //2 把本地文件復制到服務器文件中            //提供工具類,直接調用工具類方法實現            //兩個參數:第一個參數本地文件,第二個參數服務器文件            FileUtils.copyFile(upload, serverFile);        }                //獲取選擇客戶的cid值//        String scid = ServletActionContext.getRequest().getParameter("cid");//        // cid如何處理//        // 把cid值封裝到linkman對象里面//        // 把cid放到linkman的customer對象里面//        int cid = Integer.parseInt(scid);//        //放到customer里面//        Customer c = new Customer();//        c.setCid(cid);//        //把c放到linkman里面//        linkMan.setCustomer(c);                //調用service的方法聯系人信息添加到數據庫里面        linkManService.add(linkMan);                return "addLinkMan";    }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 河北省| 萨嘎县| 华容县| 梧州市| 永川市| 江川县| 汝阳县| 黎城县| 长治县| 蓬莱市| 普定县| 布尔津县| 大渡口区| 康平县| 武乡县| 涪陵区| 新乐市| 大方县| 泗阳县| 维西| 泰兴市| 绍兴市| 定远县| 澄城县| 凌源市| 奉新县| 清远市| 雅江县| 墨竹工卡县| 临潭县| 易门县| 周口市| 霍山县| 平安县| 安康市| 屏南县| 临高县| 木里| 嵊泗县| 望江县| 漠河县|