社区
Web 开发
帖子详情
请教: jsp中如何读取一张GIF,并输出来!!!
yown
2006-03-31 02:07:54
gif地址:d:/a.gif
a.jsp
<%@ page contentType="image/gif;charset=gb2312" %>
...
怎样将a.gif读出来呢???
...全文
254
9
打赏
收藏
请教: jsp中如何读取一张GIF,并输出来!!!
gif地址:d:/a.gif a.jsp ... 怎样将a.gif读出来呢???
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
9 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
yown
2006-04-05
打赏
举报
回复
jsp中图片处理相关操作
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*,java.io.*,java.awt.Image,java.awt.image.*,com.sun.image.codec.jpeg.*"%>
<html>
<body>
<%
/*
drop table imagetable;
create table imagetable
(
nid int not null,
image blob,
primary key (nid)
)
type = InnoDB;
*/
/*
//================ 一 、将文件写入到数据库的大字段中begin=====================
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost:3306/test?user=root&password=eastsoftweb";
Connection conn= DriverManager.getConnection(url);
java.io.File file = new File("d:/temp/1.jpg");
FileInputStream is=new FileInputStream(file);
PreparedStatement stmt = conn.prepareStatement(
"INSERT INTO imagetable (nid,image)" +
"VALUES (?, ?)"); //预编译SQL语句
stmt.setInt(1, 1);
stmt.setBinaryStream(2, is,(int)file.length());
stmt.executeUpdate();
stmt.close();
is.close();
out.println("update end");
//===============将文件写入到数据库的大字段中end=========================
*/
/*
//====================== 二、jsp显示服务器硬盘图片示例 begin==============
FileInputStream is=new FileInputStream("d:/temp/1.JPG");
response.reset();
response.setContentType("image/jpeg");
ServletOutputStream sos = response.getOutputStream();
byte[] buffer = new byte[1024];
int len=0;
while((len=is.read(buffer))>0){
sos.write(buffer,0,len);
}
sos.flush();
sos.close();
//=======================jsp显示服务器硬盘图片示例 end===================
*/
//===================== 三、将数据库的大字段图片还原到本地,并在网页上显示begin==============
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost:3306/test?user=root&password=eastsoftweb";
Connection conn= DriverManager.getConnection(url);
java.io.File file = new File("d:/temp/db.jpg");
FileOutputStream os=new FileOutputStream(file);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=stmt.executeQuery("select nid,image from imagetable where nid=1");
rs.next();
byte[] buffer=rs.getBytes(2);
stmt.close();
os.write(buffer);
os.flush();
os.close();
out.println("query end");
//网页上显示
response.reset();
response.setContentType("image/jpeg");
ServletOutputStream sos = response.getOutputStream();
sos.write(buffer);
sos.flush();
sos.close();
//======================将数据库的大字段图片还原到本地,并在网页上显示end===================
/*
//======================四、生成缩略图begin==============================
File file = new File("d:/temp/1.JPG");
String newurl="d:/temp/2.jpg"; //新的缩略图保存地址
Image src = javax.imageio.ImageIO.read(file); //构造Image对象
float tagsize=200;
int old_w=src.getWidth(null); //得到源图宽
int old_h=src.getHeight(null);
int new_w=0;
int new_h=0; //得到源图长
int tempsize;
float tempdouble;
if(old_w>old_h){
tempdouble=old_w/tagsize;
}else{
tempdouble=old_h/tagsize;
}
new_w=Math.round(old_w/tempdouble);
new_h=Math.round(old_h/tempdouble);//计算新图长宽
BufferedImage tag = new BufferedImage(new_w,new_h,BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src,0,0,new_w,new_h,null); //绘制缩小后的图
FileOutputStream newimage=new FileOutputStream(newurl); //输出到文件流
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(newimage);
encoder.encode(tag); //近JPEG编码
newimage.close();
//========================生成缩略图end================================
*/
%>
zx2002027
2006-03-31
打赏
举报
回复
http://www.watchina.org/html/program/Java/13645.html
yown
2006-03-31
打赏
举报
回复
当然不是本机,而且不能用<img !!!!!
weiguo028
2006-03-31
打赏
举报
回复
apache 中的 JAKATA项目组的 fileUpload组件,我实现了.
crazy_he
2006-03-31
打赏
举报
回复
<img src="file:///D|/a.gif">
十分钟年华老去
2006-03-31
打赏
举报
回复
本机的话用楼上的就可以了
zx2002027
2006-03-31
打赏
举报
回复
<img src="d:/a.gif">
yown
2006-03-31
打赏
举报
回复
不是,因为图片不在web下!!
请问,如保将指定的a.gif保存在缓存BufferedImage对像里!!!
huataixiang19810225
2006-03-31
打赏
举报
回复
用HTML标签加上图片路径就可以啊,最多在jsp中多一个输出的处理
如何实现导入Word文档到ueditor编辑器
中
怎么将本地地址搞成文件,我查阅了好久好久的资料,还
请教
了各路大神(骚骚的三水,和传说
中
的周皇),得到一个结论,单纯前端不可能通过本地地址拿到文件(于是第一条解决思路出来了,在执行 罪魁祸首代码 之前,将...
ckeditor集成Word导入功能
怎么将本地地址搞成文件,我查阅了好久好久的资料,还
请教
了各路大神(骚骚的三水,和传说
中
的周皇),得到一个结论,单纯前端不可能通过本地地址拿到文件(于是第一条解决思路出来了,在执行 罪魁祸首代码 之前,将...
富文本编辑器实现导入ppt
怎么将本地地址搞成文件,我查阅了好久好久的资料,还
请教
了各路大神(骚骚的三水,和传说
中
的周皇),得到一个结论,单纯前端不可能通过本地地址拿到文件(于是第一条解决思路出来了,在执行 罪魁祸首代码 之前,将...
一些重要的面试题!
本文对Java
中
常见的单例模式写法做了一个总结,如有错漏之处,恳请读者指正。饿汉法顾名思义,饿汉法就是在第一次引用该类的时候就创建对象实例,而不管实际是否需要创建。代码如下:1234567public class Singleton ...
nginx+uwsgi 心得集
所有静态文件由nginx直接
读取
不经过tomcat或resin location ~ .*.(htm|html|
gif
|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma) e x p i r e s 15 d ; l o c a t i o n . ∗ . ( j s ...
Web 开发
81,116
社区成员
341,730
社区内容
发帖
与我相关
我的任务
Web 开发
Java Web 开发
复制链接
扫一扫
分享
社区描述
Java Web 开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章