请教一个关于Servlet的很奇怪的问题..~~~~~~~~~~!!!!!!!!!!!!!!!

glaciall 2006-09-04 04:24:55
import java.io.IOException;
import java.io.PrintStream;
import javax.servlet.*;
import javax.servlet.http.HttpServlet;

public class Test extends HttpServlet
{

public PrintStream out;

public Test()
{
out = null;
}

public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException
{
if(out == null)
{
out = new PrintStream(response.getOutputStream());
}
out.println("Hello World.");
}
}

俺比如说吧,这样的一段代码,在Tomcat5.5.17上,弄好之后,打开页面,狠狠的刷,一般情况下都还正常的,可就是有时会没有结果,连着刷很多下,都会无结果,不会有任何的输出,而在另外一个Servlet里面,我在试了,同时处理这个请求响应,还用context.log()方法把这个给记录了下来,结果表明,这个确实被调用了,可是有时确确实实没有输出,真的是百思不得其解,求助.
...全文
533 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
glaciall 2006-09-04
  • 打赏
  • 举报
回复
法克,还是一样的..嘎嘎.
glaciall 2006-09-04
  • 打赏
  • 举报
回复
可能是缓冲区的问题,我加了response.flushBuffer()看看...

NNDX...

刷./.
glaciall 2006-09-04
  • 打赏
  • 举报
回复
可是,也不可能会出现我现在说的这事啊,本地的,也不会久久都打不开,再说,刚刚,有看到几次没有输出的结果,一下子全都输出了,难道是servlet或tomcat自身的的一些机制???????
jihanzhong 2006-09-04
  • 打赏
  • 举报
回复
html 协议和网络延迟之类的原因引起的8,尽管你是本地的,也要发布通过html协议走啊,又不是.html文件直接打开的
glaciall 2006-09-04
  • 打赏
  • 举报
回复
哎,对了,有时,它会把好几次没有输出的东西,一次性的全显示出来...

我真的晕了..这是虾米东东啊...
glaciall 2006-09-04
  • 打赏
  • 举报
回复
回魔鬼代言人:

我的意思是说,我在另外一个Servlet里面,再做了个测试,也就是在service()方法里,每次接受到请求了,都用context.log方法在日志里记录一下,发现每次都会有记录,但是有时就是灭有输出..
glaciall 2006-09-04
  • 打赏
  • 举报
回复
在J2EE的API参考里有这么个:

ServletResponse的getWriter()方法里会抛出这个异常,

IllegalStateException - if the getOutputStream method has already been called
for this response object

而它的getOutputStream()方法里会抛出这个异常.

IllegalStateException - if the getOutputStream method has already been called for this response object

并且两者的函数申明里都有这么样的一句
Either this method or getOutputStream() may be called to write the body, not both.
Either this method or getWriter() may be called to write the body, not both.
真晕了....

还有pauliuyou(paul)的方法并未能解决问题...

真晕,是有地方冲突么???

期待高人来解说一下...
  • 打赏
  • 举报
回复
帮你顶?
顺便学习,“在另外一个SERVLET里面”是指在“另个一个JSP页面吗?”
glaciall 2006-09-04
  • 打赏
  • 举报
回复
谢谢楼上两位.呵呵 ...
mingyuan1983 2006-09-04
  • 打赏
  • 举报
回复
也帮顶一下吧
jsfhua 2006-09-04
  • 打赏
  • 举报
回复
帮你顶一下
glaciall 2006-09-04
  • 打赏
  • 举报
回复
我记得之前有个错误提示,好想是跟这个out有关的...

是怎么回事呢?
glaciall 2006-09-04
  • 打赏
  • 举报
回复
楼上的,你那跟我的有什么不同的或者说,为什么要你那样子呢?
pauliuyou 2006-09-04
  • 打赏
  • 举报
回复
PrintWriter out = response.getWriter();
out.println();
glaciall 2006-09-04
  • 打赏
  • 举报
回复
-_-!!

是本地的,嘎嘎,晕倒了....
jihanzhong 2006-09-04
  • 打赏
  • 举报
回复
有可能是网络原因

81,114

社区成员

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

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