Solved

Http request and servlets

Posted on 2003-11-05
5
190 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

758 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now