jsp图片在网页上不能显示

jsp图片在网页上不能显示,第1张

2个情况,1看看字符编码有没有问题,我看你的页面是include的。编码不对有时候会出现乱码和什么的加载不正常 2右键属性,看看的地址对不对~把地址单独复制到浏览器里看看能不能打开。

还是给你个例子来的比较实际,sql *** 作台二进制数据

<%@ page contentType="text/html;charset=gb2312"%>

<%@ page import="javasql,javaio,javaawtImage,javaawtimage,comsunimagecodecjpeg"%>

<html>

<body>

<%

/

drop table imagetable;

create table imagetable

(

id int not null,

image image,

primary key (id)

)

/

/

//================ 一 、将文件写入到数据库的大字段中begin=====================

ClassforName("commicrosoftjdbcsqlserverSQLServerDriver");

String url ="jdbc:microsoft:sqlserver://127001:1433;DataBaseName=zl";

Connection conn= DriverManagergetConnection(url,"sa","1234");

File file = new File("e:/1jpg");

FileInputStream is=new FileInputStream(file);

PreparedStatement stmt = connprepareStatement(

"INSERT INTO imagetable (id,image)" + "VALUES (, )");

stmtsetInt(1, 1);

stmtsetBinaryStream(2, is,(int)filelength());

stmtexecuteUpdate();

stmtclose();

isclose();

outprintln("恭喜你,你成功加入一张!");

//===============将文件写入到数据库的大字段中end=========================

/

/

//====================== 二、jsp显示服务器硬盘示例 begin==============

FileInputStream is=new FileInputStream("e:/1jpg");

responsereset();

responsesetContentType("image/jpeg");

ServletOutputStream sos = responsegetOutputStream();

byte[] buffer = new byte[1024];

int len=0;

while((len=isread(buffer))>0){

soswrite(buffer,0,len);

}

sosflush();

sosclose();

//=======================jsp显示服务器硬盘示例 end===================

/

//===================== 三、将数据库的大字段还原到本地,并在网页上显示begin==============

ClassforName("orggjtmmmysqlDriver")newInstance();

String url ="jdbc:mysql://localhost:3306/testuser=root&password=eastsoftweb";

Connection conn= DriverManagergetConnection(url);

javaioFile file = new File("d:/temp/dbjpg");

FileOutputStream os=new FileOutputStream(file);

Statement stmt=conncreateStatement(ResultSetTYPE_SCROLL_SENSITIVE,ResultSetCONCUR_READ_ONLY);

ResultSet rs=stmtexecuteQuery("select nid,image from imagetable where nid=1");

rsnext();

byte[] buffer=rsgetBytes(2);

stmtclose();

oswrite(buffer);

osflush();

osclose();

outprintln("query end");

//网页上显示

responsereset();

responsesetContentType("image/jpeg");

ServletOutputStream sos = responsegetOutputStream();

soswrite(buffer);

sosflush();

sosclose();

//======================将数据库的大字段还原到本地,并在网页上显示end===================

/

//======================四、生成缩略图begin==============================

File file = new File("d:/temp/1JPG");

String newurl="d:/temp/2jpg"; //新的缩略图保存地址

Image src = javaximageioImageIOread(file); //构造Image对象

float tagsize=200;

int old_w=srcgetWidth(null); //得到源图宽

int old_h=srcgetHeight(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=Mathround(old_w/tempdouble);

new_h=Mathround(old_h/tempdouble);//计算新图长宽

BufferedImage tag = new BufferedImage(new_w,new_h,BufferedImageTYPE_INT_RGB);

taggetGraphics()drawImage(src,0,0,new_w,new_h,null); //绘制缩小后的图

FileOutputStream newimage=new FileOutputStream(newurl); //输出到文件流

JPEGImageEncoder encoder = JPEGCodeccreateJPEGEncoder(newimage);

encoderencode(tag); //近JPEG编码

newimageclose();

//========================生成缩略图end================================

/

%>

以上就是关于jsp图片在网页上不能显示全部的内容,包括:jsp图片在网页上不能显示、Jsp页面中本地图片显示不了、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/10185558.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-06
下一篇2023-05-06

发表评论

登录后才能评论

评论列表(0条)

    保存