springMVC 动态显示图片

html jsvar myDate = new Date(); $("#uploadpic").attr("src",'<%=path%>/activity/getpic.do?filename='+file.name+"&random="+myDate.getTime()); java@RequestMapping("getpic")public void getpic(HttpServletResponse response,HttpServletRequest request,String filename,String random){ System.out.println(filename); System.out.println(random); String uploadDir = request.getRealPath("/")+"daypic"; String sep = System.getProperty("file.separator"); File uploadedFile = new File(uploadDir + sep + filename); try { FileInputStream inputStream = new FileInputStream(uploadedFile); byte[] data = new byte[(int)uploadedFile.length()]; int length = inputStream.read(data); inputStream.close(); response.setContentType("image/png"); OutputStream stream = response.getOutputStream(); stream.write(data); stream.flush(); stream.close();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();} }

你可能感兴趣的:(java)