发布网友 发布时间:2022-04-22 00:48
共1个回答
热心网友 时间:2023-07-01 01:46
jsp: <input id="file" name="doc" type="file" style="position:absolute;filter:alpha(opacity=0);width:152px;height:120px;top:40px;left:10px" >
public String dbUpload(){
ActionContext ctx = ActionContext.getContext();
HttpServletRequest req = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
MultiPartRequestWrapper wrapper = (MultiPartRequestWrapper)req;
File doc =wrapper.getFile("doc");
String fileName=null;
if(doc!=null){
fileName="/"+String.valueOf(System.currentTimeMillis())+"."+wrapper.getContentTypes("doc")[0].substring(6);
try {
// String dri=req.getRealPath("img"); //代表图片上传的地方为img文件夹里
String dri=imagdirectory;
File target =new File(dri+fileName);
FileUtils.copyFile(doc, target);
}catch(Exception e) {
e.printStackTrace();
}finally {
if(doc.exists()){
doc.delete();
}
}
}
return fileName;
}