Method 1. save the image to the specified path on the hard disk and write the image content to the output stream. The public static void showPic (String pic, HttpServletResponse response) {try {InputStream inputStream = null; servletOutputStream outputStream = response. getOutputStream (); response. reset (); response. setContentType ("image/jpeg"); String savePath = ""; // system file path String globalPath = FileUploadContext. getGlobalPath (); if (globalPath = null) {globalPath = "D: // software/ /";} SavePath = globalPath + pic; try {inputStream = new FileInputStream (savePath); int bufferSize = 4096; byte [] B = new byte [bufferSize]; int n = 0; do {n = inputStream. read (B); if (n> 0) {outputStream. write (B, 0, n) ;}} while (n> 0); outputStream. flush ();} finally {if (inputStream! = Null) {inputStream. close ();} if (outputStream! = Null) {outputStream. close () ;}} catch (IOException e) {logger. error (e. getMessage () ;}} public static String uploadPic (HttpServletRequest req, String errorPic) {MultipartFile file = (DefaultMultipartHttpServletRequest) req ). getFile ("pic"); String fileName = errorPic; if (file! = Null & file. getSize ()> 0) {try {if (file. getSize ()> 10000000) {throw new BaseException ("Upload Failed: the file size cannot exceed 10 MB");} String picPath = FileUploadContext. getGlobalPath (); fileName = FileUploadContext. nextFileName (); int point = fileName. lastIndexOf (". "); fileName = fileName. substring (0, point); String realFileName = file. getOriginalFilename (); int len = realFileName. length (); point = realFileName. lastIndexO F ("."); String prefix = realFileName. substring (point, len); if (prefix. equals ("") {throw new IllegalArgumentException ("file has no extension! ");} Else if (prefix. equalsIgnoreCase (". jpg ") | prefix. equalsIgnoreCase (". gif ") | prefix. equalsIgnoreCase (". bmp ") {// system. out. println ("upload file type is" + prefix); fileName = fileName + prefix;} else {throw new IllegalArgumentException ("file type error! ");} String fileFullName = picPath + fileName; File destFile = new File (fileFullName); file. transferTo (destFile);} catch (Exception e) {logger. error (e. getMessage (); return fileName;} Method 2: Save the image to the blob field of the database (if the table data volume is large, it is not recommended) public static byte [] savePic (ServletContext context, String fileName) {byte [] buf = null; // 10k cache try {String picPath = context. getRealPath ("WEB-INF"); int point = PicPath. lastIndexOf (File. separator); picPath = picPath. substring (0, point); picPath = picPath + fileName; FileInputStream imgis = new FileInputStream (picPath); int n = 0; ByteArrayOutputStream out = new ByteArrayOutputStream (4096 ); byte [] B = new byte [4096]; try {while (n = imgis. read (B ))! =-1) {out. write (B, 0, n) ;}} finally {if (imgis! = Null) {imgis. close () ;}} buf = out. toByteArray ();} catch (IOException e) {logger. error (e. getMessage ();} return buf;} public static void showPic (HttpServletResponse response, byte [] B) {try {ServletOutputStream outputStream = response. getOutputStream (); response. reset (); response. setContentType ("image/jpeg"); try {outputStream. write (B, 0, B. length); outputStream. flush ();} finally {if (outputSt Ream! = Null) {outputStream. close () ;}} catch (IOException e) {logger. error (e. getMessage ());}}