• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what's the problem with this code...

 
Leandro Oliveira
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the problem with this code? it never enters the body of the loop and if requested in tomcat 4.x an exception is thrown after a period of attempt, if requested in tomcat 5.x the screen keeps blank...
thanks in advance!
 
Raj Neets
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can please say what was the error thrown. Before that trying closing the inputstream that u have opened with the request object.
 
X. Li
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to run your code with WSAD4.01, the result is blank page without any exceptions. I don't understand what's your purpose to run it. If you want to test service method (no implementation for do*** methods), a better way is to remove some noisy codes like
ServletInputStream in=request.getInputStream();
ServletOutputStream out=response.getOutputStream()
so that you can get more clear result.
 
Leandro Oliveira
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The purpose of this code is write to the outputstream the same writen to the input stream by the browser... If you try to run this code under tomcat 4.x your going to have ServletException thrown at the line of the loop (while( (read=in.read(buff))!=-1 )...) in other words, it looks like ServletInputStream.read can't read...
 
Leandro Oliveira
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try looking at your stdout, your going to see only:
'Starting all...'
 
X. Li
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I did see "Starting all..." only in console. I run all your code with WSAD without any problems. Sorry, I don't have Tomcat so I can't say about it. But I believe it has nothing to do with SCWCD.
 
Moorthi Ramasamy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Leandro,
What's your HTTP method. Is it POST/PUT or GET??. I double checked with servlet spec (SRV.14.2.14), You can call ServletRequest.getInputStream()only for HTTP POST & PUT methods.
Thanks,
Moorthi.
 
Leandro Oliveira
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using GET method...
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect that the problem is that the InputStream has not been flushed on the client and there are less bytes to be read than your buffer size. If you know that there is some data on the stream, try reading a byte at a time and see what happens. Also, as mentioned earlier, you should not be overriding the service methods for HttpServlet. In your case you should override the doGet method.
 
Leandro Oliveira
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it looks like Moorthi Ramasamy provided the solution, I requested the servlet with method post and it did work...
From specification, SRV.14.2.14, and SRV.14.2.16, It is said that the ServletInputStream is for reading request body, and a simple request doesn't have body...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic