
在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()
in.close()
o.close()
%>
jsp页面gif图片不显示有两种原因,
可能是工程中的资源不存在该图片信息。
可能是在jsp页面图片位置写错了。通常来说,图片,css,js,等,都应该用到相对路径才能使jsp在服务器上正常显示和 *** 作。至于相对路径,可以是jsp上面定义好的
//第一种是:String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"
<Img src="<%=basePath%>/images/image.gif"></img>
//另一种是在位置前面直接加el表达式
"src = ${pageContext.request.contextPath}/images/image.gif"
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)