sevlet里面httpURLConnection了一个网址,怎么doGet重复执行了10次???

unm 2011-02-10 05:08:07
sevlet里面httpURLConnection了一个网址,怎么doGet重复执行了10次???

另一个sevlet没有httpURLConnection获取数据,正常执行的一次

两个sevlet的区别就是 重复的这个用httpURLConnection get了一个网页的数据

怎么这么奇怪???


谁碰到过吗? 而且,为什么是10很奇怪,不知道怎么来的,sevlet里再没什么其他东西了
...全文
127 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
unm 2011-02-10
  • 打赏
  • 举报
回复
换方法执行了,反正chrome取得MP3文件的时候,需要到服务器上好几次的,如果每次都生出那就太耗费资源了,做了个缓存,就这样吧,结帖了
wxjlogo 2011-02-10
  • 打赏
  • 举报
回复
又一个未解之谜啊 没找出来
whut_lcy 2011-02-10
  • 打赏
  • 举报
回复
感觉 res.reset()有点可疑
rainsilence 2011-02-10
  • 打赏
  • 举报
回复
粗看你的代码getAudio这个函数应该是编译不通过的。
定义的时候有三个参数,调用的时候只写了两个。
还有你的getAudio中的baos变量new完后就直接返回了????
还有你的getAudio的参数传进去完全没用到啊
unm 2011-02-10
  • 打赏
  • 举报
回复
这是get方法
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

res.reset();
ByteArrayOutputStream baos = getAudio(req,res);// 在此调用取得服务器的数据
res.setContentType("audio/mpeg");
java.io.OutputStream os = res.getOutputStream();
os.write(baos.toByteArray());
os.flush();
os.close();
}
这是调用的取服务器数据的,
public ByteArrayOutputStream getAudio(String response,HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
HttpURLConnection httpURLConnection = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
{
URL url = new URL("http://www.baidu.com/");// 提交地址
httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("GET");// 设置提交方法
httpURLConnection.setRequestProperty("Accept-Language","zh-CN,zh;q=0.8");
httpURLConnection.setRequestProperty("Cache-Control","max-age=0");
httpURLConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10");
httpURLConnection.connect();

httpURLConnection.disconnect();//断开连接
}
catch (Exception e)
{
httpURLConnection.disconnect();//断开连接
System.out.println(e.getMessage());
e.printStackTrace();
}
return baos;
}



shit,doget()为什么会执行这么多遍啊。。。。。。。

这个就执行了5遍,。。。。。。。。。。。。。。


现在测试到这里:
如果只有这几行
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

ByteArrayOutputStream baos = new ByteArrayOutputStream();
res.setContentType("audio/mpeg");
java.io.OutputStream os = res.getOutputStream();
os.write(baos.toByteArray());
os.flush();
os.close();

}

那么会执行3遍,用ie试,也是3遍。。。。。。。。。。。。。。。。。。。。。。。。

这个时候,猜测是浏览器中的播放器根据数据不断的重复提交申请吧

不过,chrome会对audio/mpeg提交10次请求????疯了

而且,我在session里面,怎么能把这10次请求变成我自己资源的一次请求呢???

我怎知是不是同一个session里面的是用户请求还是chrome请求????
unm 2011-02-10
  • 打赏
  • 举报
回复
破玩意查了半天,哪里有递归啊

我在想是不是 httpURLConnection 导致什么重新post,疯了
iambic 2011-02-10
  • 打赏
  • 举报
回复
递归了吧。
heardy 2011-02-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 inhibitory 的回复:]
有可能是因为10是一个很好的数字,十全十美,
[/Quote]
Inhibitory 2011-02-10
  • 打赏
  • 举报
回复
有可能是因为10是一个很好的数字,十全十美,

81,092

社区成员

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

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