eclipse下找不到图片,请大神帮忙!
我制作的类:
package samples.javabean;
import java.awt.Color;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageOutputStream;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import org.jgraph.JGraph;
import org.jgraph.graph.DefaultCellViewFactory;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultGraphModel;
import org.jgraph.graph.DefaultPort;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphLayoutCache;
import org.jgraph.graph.GraphModel;
public class Graphic {
String webroot;
String filename;
String random;
public Graphic()
{
webroot="e:\\workspace\\DBtest\\res";
filename="number.png";
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public String getRandom() {
return random;
}
public void setRandom(String random) {
this.random = random;
}
public void paint()
{
GraphModel model=new DefaultGraphModel();
GraphLayoutCache view=new GraphLayoutCache(model,new DefaultCellViewFactory());
JGraph graph=new JGraph(model,view);
DefaultGraphCell cell=new DefaultGraphCell(random);
GraphConstants.setBounds(cell.getAttributes(),new Rectangle2D.Double(0,0,100,40));
GraphConstants.setGradientColor(cell.getAttributes(),Color.orange);
GraphConstants.setOpaque(cell.getAttributes(),true);
DefaultPort port=new DefaultPort();
cell.add(port);
graph.getGraphLayoutCache().insert(cell);
JFrame frame=new JFrame();
frame.getContentPane().add(new JScrollPane(graph));
frame.pack();
frame.setVisible(false);
try{
File f=new File(webroot,filename);
ImageOutputStream ios=ImageIO.createImageOutputStream(f);
BufferedImage img=graph.getImage(graph.getBackground(),1);
ImageIO.write(img,"png",ios);
ios.flush();
ios.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
调用的此类的jsp文件:
<%@ page language="java" contentType="text/html; charset=GB2312"
pageEncoding="GB2312"%>
<%@ page import="samples.javabean.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>图形绘制</title>
</head>
<body>
<font size=2>
<jsp:useBean id="image" class="samples.javabean.Graphic" scope="page"/>
<jsp:setProperty name="image" property="random" value="<%=session.getId().substring(0,5) %>"/>
javabean的类:<%=image.getClass().getName() %><br>
随机字符串为:<jsp:getProperty name="image" property="random"/><br>
<%image.paint(); %>
图形随机字符串:
<img src="<jsp:getProperty name="image" property="filename"/>"/><br>
</font>
</body>
</html>
在eclipse中执行的结果如下
javabean的类:samples.javabean.Graphic
随机字符串为:DB5D6
图形随机字符串: X
(X表示打不开图片)
其中res是我在项目中创建的源文件夹,按网上一些人的说法是可以正常显示的,但就是不行。
在IE中执行的结果如下:
javabean的类:samples.javabean.Graphic
随机字符串为:DB5D6
图形随机字符串: A
(A表示可以正常显示图片)
卡了我好长时间了,请大神帮忙看一下,是怎么回事?
[最优解释]
看jsp生成的html,里面的img的src是什么,然后单独显示看看。
[其他解释]
javabean的类:
随机字符串为:
图形随机字符串:X "/>
打不开,也找不到类
[其他解释]
html文件下,图片的路径为http://localhost:8080/DBtest/%3Cjsp:getProperty%20name=
[其他解释]