搞了我一下午,郁闷死啦
webwork 修改图片报错 webwork上传图片,没有选择,表单VO 获取不到值,或 String testFck = ServletActionContext.getRequest().getParameter("testFck"); 获取为空 添加上传图片,则没有错 即:<input type="file" name="files" id="upload" size="15" /> 必须赋值,但是业务需求,有时候不需要更改头像,则无法完成 解决方案:动态创建表单 function uploadPhoto() { var TEMP = '<input type=\"file\" name="files" id=\"upload\" size=\"15\" /><input type=\"button\" name="btn" id=\"btn\" value=\"取消\" onclick=\"quxiao()\"/>'; document.getElementById('uploadPhoto').innerHTML = TEMP; } function quxiao() { document.getElementById('uploadPhoto').innerHTML = ''; } JSP <a href ="#" onclick="uploadPhoto()"><img src="<%=path %>/upload/<ww:property value = "#request['MAVIN'].expertPhoto" />" width="80" height="60" /></a> <div id="uploadPhoto"></div><span>点击修改图片</span> </td> ACTION System.out.println("***********修改保存专家信息***********"); TbExpertVO expertVO = new TbExpertVO(); //获取 FCK 内容 long mavinId = expert.getExpertId(); String testFck = ServletActionContext.getRequest().getParameter("testFck"); System.out.println("testFck = "+ testFck); expertVO.setExpertId(mavinId); expertVO.setExpertInfor(testFck); expertVO.setExpertName(expert.getExpertName()); expertVO.setExpertOnline(expert.getExpertOnline()); // 文件上传处理 String destPathString = ""; String fileName = ""; if(files != null) { File file = files[0]; // 第一个图片 - one // 保证图片名唯一 String tName = filesFileName[0]; System.out.println("文件上传原图片名字:"+tName); String endPhoto = tName.substring(tName.lastIndexOf("."),tName.length()).toLowerCase(); // 处理中文图片名字不显示 String fn = String.valueOf(System.currentTimeMillis()+filesFileName[0].hashCode()); System.out.println("中文处理后的图片名字:"+fn); System.out.println("保存的图片:"+fn+" "+endPhoto); fileName = fn+endPhoto; //文件转移到 upload 下面 destPathString = ServletActionContext.getRequest().getRealPath("upload")+File.separator+fileName; System.out.println("临时文件的保存路径:"+file.getPath()+"\n"+"图片保存路径:"+destPathString); FileUtilTwo c = new FileUtilTwo(file.getPath(), destPathString); c.doCopy(); } if (!fileName.equals("")) { expertVO.setExpertPhoto(fileName); // 图片压缩处理 - 小图片 small_ xx name ImageCompressHead ic = new ImageCompressHead(); ic.setImageSmall(destPathString); } try { mavinService.modifyUpdateMavin(expertVO); } catch (BOException e) { e.printStackTrace(); } // 查询对象 返回 修改 新页面 TbExpert mavin = new TbExpert(); try { mavin = mavinService.editMavin(String.valueOf(mavinId)); } catch (BOException e) { e.printStackTrace(); } try { Clob clob = mavin.getExpertInfor(); String FCK = IOUtils.toString(clob.getCharacterStream()); ServletActionContext.getRequest().setAttribute("FCK",FCK); } catch (IOException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } ServletActionContext.getRequest().setAttribute("MAVIN",mavin); ServletActionContext.getRequest().setAttribute("SAVE_SUCCESS","SAVE_SUCCESS"); return SUCCESS;