Solved

Http request and servlets

Posted on 2003-11-05
5
195 Views
Last Modified: 2013-11-24
Hi all
I wrote a simple servlet with the following doGet method:

public void doGet (HttpServletRequest request, HttpServletResponse response)
                    throws ServletException, IOException
            {                        
                          PrintWriter out = response.getWriter();

                          Random rand = new Random();
                          int n = 500000;
                          int id = rand.nextInt(n+1);

                          response.setStatus(STATUS_CREATED);
                          response.setHeader("X-XD_RC",""+id);                          
                          response.setContentLength(0);
                          out.flush();                          
                          out.close();
            }

I run it under tomcat 4.0.6.
While accessing this servlet using a browser, I open a sniffer and what I see is that I get FIN signal from the servlet only after 1 minutes.
The browser use http 1.1 and when I change it to 1.0 and sniff it again, I receive the FIN immediate.
Why using 1.1 returns this siganl after a minute? How can I change it?
Is it the Servlet or web server configuration?

         Thanks
0
Comment
Question by:dannysh
  • 3
  • 2
5 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 9693172
 Does this matter as long as you get a valid response in both HTTP1.0 and HTTP1.1?
0
 

Author Comment

by:dannysh
ID: 9693309
Hi girionis

Sure it's matter, cause the servlet also serves http clients (other then browser) which requiers the FIN signal in order to know when the content ended.
In such situation, they will have to wait 1 minute to start working on the contenet.

0
 
LVL 35

Expert Comment

by:girionis
ID: 9693462
 Ok I see the point.

  I do not know why it is doing it. Does it happen with every Servlet? And does it happen with every Servlet that uses HTTP1.1(or 1.0)?

  FIN is actually a TCP/IP signal, so at a *guess* it probably has to do with the TCP/IP protocol. Why don't you read the content length from, the HTTP Header so you know when you've read all the data?
0
 

Author Comment

by:dannysh
ID: 9693546
Hi
>> And does it happen with every Servlet that uses HTTP1.1(or 1.0)

It happens if the client send the request in http1.1, If it 1.0 the FIN returns immediate.

>>Why don't you read the content length from

This is a kind of a solution but I don't want to work hard, I want to use a built in mechanism (TCP/IP protocol).

BTW I get the same behavior for all servlet.

What can I do?
0
 
LVL 35

Accepted Solution

by:
girionis earned 50 total points
ID: 9693620
  Your best bet is to read the HTTP/1.1 specification or ask a question to any HTTP related mailing list/EE category as this is obviously an HTTP issue.

  I also find some links that might be of interest to you:

http://www.pwg.org/hypermail/ipp/4299.html
http://www.pwg.org/hypermail/ipp/4302.html

  Apart from that I am not sure what else I could recommend :(
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question