Java reads the local picture and displays it on the JSP page by streaming

Source: Internet
Author: User

The Java code in the project is as follows:

@RequestMapping ("Readimage") Public voidReadimage (model, httpservletrequest request, httpservletresponse response)throwsioexception{String Magazineid= Request.getparameter ("Magazineid"); String SQL= "Select Save_path,save_name,extention from ta_horizon_info WHERE object_id = '" + Magazineid + "'"; Map<string, object> map = access.getsinglemap (sql,NULL); String Savepath= (String) map.get ("Save_path"); String Savename= (String) map.get ("Save_name"); String extention= (String) map.get ("Extention"); String FilePath= Savepath + "/" +savename + "." +extention; File Filepic=NewFile (FilePath); if(Filepic.exists ()) {FileInputStream is=NewFileInputStream (filepic); inti = is.available ();//Get File Size       byteData[] =New byte[i]; Is.read (data); //Read DataIs.close (); Response.setcontenttype ("image/*");//set the returned file typeOutputStream toclient = Response.getoutputstream ();//gets the object that outputs the binary data to the clientToclient.write (data);//Output DataToclient.close (); }}

JSP page code:

<style= "width:100%; height:490px"  src= "<%= Request.getcontextpath ()%>/horizon/module/magazine/readimage.wf?magazineid=${magazine.id} "> 

Java reads the local picture and displays it on the JSP page by streaming

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.