Examples of obtaining local images by JSP and details of obtaining instances by jsp
Examples of obtaining local Images Using JSP
In IE Versions later than 7, you cannot directly write a local hard disk address on src to display images. Because we can only display images on the foreground by reading binary streams in response in the background.
The Code is as follows:
Public void showPicture () {String id = ServletActionContext. getRequest (). getParameter ("id"); // The primary key id of the object class in the saved image path from the front-end. HttpServletResponse response = ServletActionContext. getResponse (); // struts2 get response if (id! = Null &&! "". Equals (id) {this. classicCases = this. classicCasesManager. findClassicCasesById (id); String pic_path = this. classicCases. getImagesLocalPath (); // The image path FileInputStream is; try {is = new FileInputStream (pic_path); int I = is. available (); // get the file size byte data [] = new byte [I]; is. read (data); // read data is. close (); response. setContentType ("image/*"); // set the returned file type OutputStream toClient = response. getOutputStream (); // get the toClient object that outputs binary data to the client. write (data); // output data toClient. close ();} catch (FileNotFoundException e) {e. printStackTrace ();} catch (IOException e) {e. printStackTrace ();}}}
The jsp page is simple. The path format is http: // localhost: 8080/projectName/*. action: prama = XXX.
ClassicCasesAction!showPicture.action?id=${classicCases.id}">
If you have any questions, please leave a message or go to the community on this site for discussion. Thank you for reading this article. Thank you for your support!