jsp中引用本地图片
2013-08-15 15:15
155 查看
在web应用中是不能访问本地文件De,可以把要引用的文件移到项目中,通过相对路径获取。有时候我们就是需要访问本地文件,那么我们可以通过流的形式传入。例如:
在showPic.jsp中:<body>
<img align="top" src="<%=request.getContextPath()%>/viewListener/viewWareCamera/picCreate.jsp?ppath=<bean:write
name='cameraOperateForm' property='picture_postion'/>" width="500" height="400" id="imgg"/>
</body>
在这里,我们的src通过调用另一个jsp来实现。并且也可以根据需要向另一个jsp传值。
那么,在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();
out.clear();
out = pageContext.pushBody();
in.close();
o.close();
%>
这样就可以实现显示本地的文件或图片。
在showPic.jsp中:<body>
<img align="top" src="<%=request.getContextPath()%>/viewListener/viewWareCamera/picCreate.jsp?ppath=<bean:write
name='cameraOperateForm' property='picture_postion'/>" width="500" height="400" id="imgg"/>
</body>
在这里,我们的src通过调用另一个jsp来实现。并且也可以根据需要向另一个jsp传值。
那么,在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();
out.clear();
out = pageContext.pushBody();
in.close();
o.close();
%>
这样就可以实现显示本地的文件或图片。
相关文章推荐
- JSP中<img>标签引用本地图片
- java项目jsp中如何引用本地路径图片
- java项目jsp中如何引用本地路径图片
- java读取本地图片并在jsp中显示
- JSP页面如何显示本地图片
- JSP显示本地图片的方法
- jsp中js实现本地图片预览基本功能
- JSP页面如何显示本地图片
- KindEditor4 struts2 jsp 本地图片或文件上传
- react页面中引用本地图片的方法
- jsp显示本地图片
- tomcat中jsp引用图片img的src属性带中文路径无法显示的解决
- 【react】页面中引用本地图片
- Jsp&Servlet实现读取本地图片并展示
- JSP页面如何显示(绝对路径)本地图片
- jsp显示本地图片
- jsp预览本地上传图片
- tomcat中jsp引用图片不能包含中文路径
- java 通过流的方式读取本地图片并显示在jsp 页面上(类型以jpg、png等结尾的图片)
- 【Bootstrap】本地css样式放置的位置,以及jsp文件中如何引用样式