首页 > 编程知识 正文

jsp获取本地图片的实例详解(java web项目中读取本地图片)

时间:2023-12-02 21:07:30 阅读:311450 作者:TJAK

本文目录一览:

  • 1、如何用JSP读取一个本地的图片,然后返回给浏览器啊?
  • 2、java 读取本地图片显示在jsp页面上
  • 3、jsp如何显示本地图片
  • 4、jsp怎么读取本地图片
  • 5、jsp 读取图片

如何用JSP读取一个本地的图片,然后返回给浏览器啊?

参考这个看看吧 out.clearBuffer(); // 如果使用JSP,需要加上这一句 OutputStream os = response.getOutputStream(); // 页面输出流,jsp/servlet都可以 response.addHeader("Content-Disposition", new String(("attachment; filename=" + filename).getBytes("GBK"), "ISO-8859-1")); // 针对中文文件名 File f = new File("d:/temp/123456.gif"); // 你的文件 InputStream is = new FileInputStream(f); // 文件输入流 byte[] bs = new byte[1024]; // 读取缓冲区 int len; while((len=is.read(bs))!=-1){ // 循环读取 os.write(bs,0,len); // 写入到输出流 } is.close(); // 关闭 os.close(); // 关闭

java 读取本地图片显示在jsp页面上

这个图片必须放在服务器,不然只有自己能看到

img src="数据库读出图片地址" /

jsp如何显示本地图片

方法/步骤

1

这个方法就是设置虚拟目录,也就是说把硬盘上一个目录映射到tomcat的工作目录下,然后tomcat就可以根据一个映射关系找到硬盘中的文件了

2

我们在Eclipse中找到服务器,下面有个server.xml文件,点击打开

方法/步骤

1

这个方法就是设置虚拟目录,也就是说把硬盘上一个目录映射到tomcat的工作目录下,然后tomcat就可以根据一个映射关系找到硬盘中的文件了

2

我们在Eclipse中找到服务器,下面有个server.xml文件,点击打开

jsp怎么读取本地图片

java读取本地图片并在jsp中显示

java:

public void showPicture() throws Exception

{

String picId = getRequest().getParameter("picId");

String pic_path = pointCardApplyManager.findPicturePath(picId);

System.out.println(pic_path);

FileInputStream is = new FileInputStream(pic_path);

int i = is.available(); // 得到文件大小

byte data[] = new byte[i];

is.read(data); // 读数据

is.close();

response.setContentType("image/*"); // 设置返回的文件类型

OutputStream toClient = response.getOutputStream(); // 得到向客户端输出二进制数据的对象

toClient.write(data); // 输出数据

toClient.close();

}

jsp:

div align="left"

img hspace="2" vspace="2" border="1" align="middle" height="50" width="50"

src="${ctx}/showPicture.action?picId=s:property value='#image.resourceid'/" onclick="selectForward('s:property value='#image.resourceid'/');"

/div

javascript:

function selectForward(picId){

var objForm = document.applyForm;

var url="${ctx}/showPicture.action?picId="+picId;

var openStyle="dialogHeight:500px; dialogWidth:500px; status:no; help:no; scroll:auto";

var result = window.showModalDialog(url,window.document,openStyle);

return true;

}

显示效果二:

jsp:

div align="left" id="sams:property value='#sts.count'/"

img hspace="0" vspace="0" border="0" align="middle" height="50" width="50" onmouseover="displayDiv1('lags:property value='#sts.count'/');displayDiv2('sams:property value='#sts.count'/')"

src="${ctx}/showPicture.action?picId=s:property value='#image.resourceid'/"

/div

div align="left" id="lags:property value='#sts.count'/" style="display:none"

img hspace="0" vspace="0" border="0" align="middle" height="600" width="800" onmouseout="displayDiv1('sams:property value='#sts.count'/');displayDiv2('lags:property value='#sts.count'/')"

src="${ctx}/showPicture.action?picId=s:property value='#image.resourceid'/"

/div

javascript:

function displayDiv1(name) {

document.getElementById(name).style.display="block";

}

function displayDiv2(name) {

document.getElementById(name).style.display="none";

}

jsp 读取图片

你想要的是上传图片。

但你写的,完全不是上传功能,上传的图片是保存成 流 的。

只能通过request.getInputStream()获取输入流才可以。但是,这样也不正确,纯JSP上传是很麻烦的,要考虑很多东西。如果你想上传 建议你用commons-fileupload 包 去做

那里封装好了方法,使用方便,具体方法,先去百度吧,不明白再问

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。