Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Http request and servlets

Posted on 2003-11-05
5
Medium Priority
?
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

688 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