Solved

Http request and servlets

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to configure empty element in XML Document parser? 15 58
Bot application - advice 3 81
passing enum to a method 4 51
Eclipse neon2 "Java build path" correctness 7 44
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…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

739 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