求助:如何把图片写到jsp页面上

selfsoft 2006-03-15 01:34:34
我想问问各位大虾,如何往jsp页面写图片,而不是采用链接方式做?请大虾赐教
...全文
304 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
killme2008 2006-03-16
  • 打赏
  • 举报
回复
UP
zx2002027 2006-03-15
  • 打赏
  • 举报
回复
来晚了
  • 打赏
  • 举报
回复
楼上这个<img src="xxxx.xxxx.xxxx.xxx" />不就可以么,还要什么样子的?
希偌 2006-03-15
  • 打赏
  • 举报
回复
<img src="xxxx.xxxx.xxxx.xxx" />

类里面:
response.setContentType("image/*");
polarman 2006-03-15
  • 打赏
  • 举报
回复
图片一定要用HTML标签的,可以用IMG,也可以用其他标签,设置background属性
但能直接写到jsp里,jsp最终是要转换成HTML纯文本到客户端的
至于连接到具体的图片文件还是什么Servlet,jsp之类的,只要能获取图片的文件流就行了
可以参考楼上的,用servlet
<img src="你的servlet">
treeroot 2006-03-15
  • 打赏
  • 举报
回复
up
RainRainbow 2006-03-15
  • 打赏
  • 举报
回复

String fileName = "c:/Milan.gif";

File f = new File(fileName);

if (!f.exists()) {
response.sendError(404, "File not found!");
return;
}

response.reset();

URL u = new URL("file:///" + fileName);
response.setContentType(u.openConnection().getContentType());
response.setHeader("Content-Disposition", "inline; filename="
+ f.getName());

byte[] buf = new byte[1024];
int len = 0;
BufferedInputStream br = null;
OutputStream output = null;
try {
br = new BufferedInputStream(new FileInputStream(f));
output = response.getOutputStream();
while ((len = br.read(buf)) > 0) {
output.write(buf, 0, len);
}
output.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (br != null) {
br.close();
br = null;
}
if (output != null) {
output.close();
output = null;
}
}
tklqa 2006-03-15
  • 打赏
  • 举报
回复
int width=60, height=20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

// 获取图形上下文
Graphics g = image.getGraphics();

//生成随机类
Random random = new Random();

// 设定背景色
g.setColor(getRandColor(200,250));
g.fillRect(0, 0, width, height);

//设定字体
g.setFont(new Font("宋体",Font.PLAIN,18));

//画边框
//g.setColor(new Color());
//g.drawRect(0,0,width-1,height-1);

// 随机产生155条干扰线,使图象中的认证码不易被其它程序探测到
g.setColor(getRandColor(160,200));
for (int i=0;i<155;i++)
{
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(12);
int yl = random.nextInt(12);
g.drawLine(x,y,x+xl,y+yl);
}

// 取随机产生的认证码(4位数字)
String sRand="";
for (int i=0;i<4;i++){
String rand=String.valueOf(random.nextInt(10));
sRand+=rand;
// 将认证码显示到图象中
g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));
//调用函数出来的颜色相同,可能是因为种子太接近,所以只能直接生成
g.drawString(rand,13*i+6,16);
}

// 将认证码存入SESSION
session.setAttribute("rand",sRand);

// 图象生效
g.dispose();

// 输出图象到页面
ImageIO.write(image, "JPEG", response.getOutputStream());
%>
killme2008 2006-03-15
  • 打赏
  • 举报
回复
不明白,图片不链接
还能怎么写呢?
GZ

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧