Solved

Http request and servlets

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java 1603 Error 3 50
groupNoAdj 7 84
@SBGen Method 3 35
Where to store the queries for modification of table 4 53
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
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 will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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:

919 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

19 Experts available now in Live!

Get 1:1 Help Now