IMG in JSP displays local Images

Source: Internet
Author: User

In a web application, you cannot access the local file de. You can move the file to be referenced to the project and obtain it through the relative path. Sometimes we need to access the local file, so we can pass in the form of a stream. For example:
In showpic. jsp: <body>
/viewlistener/viewwarecamera/piccreate. jsp? Ppath = <Bean: write name = 'cameraoperateform' property = 'picture _ postion '/> "width =" 500 "Height =" 400 "id =" imgg "/>
</Body>
Here, SRC is implemented by calling another JSP. You can also pass the value to another JSP as needed.
In piccreate. jsp:
<% @ Page import = "Java. Io. *" %>

<%
String ppath = request. getparameter ("ppath ");
String file = "D:/" + ppath;
Fileinputstream in = new fileinputstream (new file (File ));
Outputstream o = response. getoutputstream ();
Int L = 0;
Byte [] buffer = new byte [4096];
While (L = in. Read (buffer ))! =-1 ){
O. Write (buffer, 0, L );
}
O. Flush ();
In. Close ();
O. Close ();
%>

In this way, you can display local files or images.

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.