Servlet 高手请进。

chemain 2001-06-08 05:16:00
请问高手:
在servlet中产生了一个动态的网页,此网页中加有图片连接,在ie中访问时,此图片不能载入,我曾试着改变路径都没成功,谁能解决此问题,不胜感激!!!!
...全文
101 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
chemain 2001-06-11
  • 打赏
  • 举报
回复
bootcool(bootcool):
you coding is good.but it only load a picture,my question's essential is that picture show in html. thanks!
newroc 2001-06-09
  • 打赏
  • 举报
回复
我记得好像图片在servlet中引用的话需要在web服务器中设置应用程序映射,具体怎么设置记不太清,不好意思,希望没把你弄的更晕 :)
你把图片移到htm文件所在的目录里试试
yangzi 2001-06-09
  • 打赏
  • 举报
回复
和应用程序映射不拾界。
我想,还是路径不对。
v不吃v你 2001-06-08
  • 打赏
  • 举报
回复
//看看有用否。
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.net.*;

public class DownLoad extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType( "image/jpeg" );
response.setHeader("Content-disposition",
"attachment; filename=" +
"28-3-41530_xyx0427.jpg" );
String fileURL = "http://ent.sina.com.cn/s/28-3-41530_xyx0427.jpg";
URL url=new URL(fileURL);
BufferedInputStream bis = new BufferedInputStream(url.openStream());
BufferedOutputStream bos = new BufferedOutputStream( response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while (-1!=(bytesRead=(bis.read(buff,0,buff.length)))){
bos.write(buff,0,bytesRead);
}
if (bis!=null){
bis.close();
}
if (bos!=null){
bos.close();
}
}
}
DrunkenLion 2001-06-08
  • 打赏
  • 举报
回复
呵呵,response.setContextType("gif/jpeg");
outputstream aa = response.getOutStream();
chemain 2001-06-08
  • 打赏
  • 举报
回复
ceo99(菜猪) :

还是不行。
属性显示为:http://localhost:8100/tt/servlet/SS.jpg

我已经检查过了,就是不行。可能是servlet不重新发送就不能刷新。
不过还是谢谢你。

luodi 2001-06-08
  • 打赏
  • 举报
回复
看看产生的这个网页的HTML源文件内容究竟是什么是最快的方法。
ceo99 2001-06-08
  • 打赏
  • 举报
回复
你是说图片没显示吧?

右键点图片看一下它的属性,其中有它的位置,是不是对的?

一般是相对路径的问题。因为servlet的位置是根据context来的,而图片则不是。

如果这也不是的话,那就是你的IE没打开图片显示了。:)

81,122

社区成员

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

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