jsp页面:
测试文件上传function urlP(path){
document.getElementById("p").value=path;
}
SpringMVC框架中的对应的Controller方法:
@RequestMapping("/save")
public void save(MultipartFile upload,String p,HttpServletRequest request) throws IOException {
if(upload!=null){
String realPath = request.getSession().getServletContext().getRealPath("/WEB-INF/upload");//先获取项目的发布到的路径,再拼接出上传的文件所存放的路径
FileUtils.copyInputStreamToFile(upload.getInputStream(), new File(realPath, upload.getOriginalFilename()));//保存文件到指定位置
String filePath=realPath+"\\"+p; //只获取文件名以及扩展名
audition.setAnnuxPath(filePath);
auditionService.save(audition);
}
}