I have a very strange problem with a Java servlet. Here is the code:
Basically it takes an integer sent from the iPhone via NSURLConnection in an NSURLRequest and returns 4 lines from a text file. The lines should be the line number of the integer received, integer + 1, integer + 700 and integer + 701. Yet when I send the request the servlet sends lines 1, 2, 3 and 4 back. If I stop the iPhone app and restart it the servlet then sends lines 5, 6, 7 and 8 back. Yet I was sure that the setLineNumber() method was meant to explicitly set the line number in the file input before reading it.
I have hard coded the number 1 into the iPhone app for testing so that is not a problem and checked that the servlet is receiving the correct number on the server side. Does anyone have any idea what could be happening?
Code:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
processRequest(request, response);
PrintWriter out = response.getWriter();
out.println(response.getHeader("line_one"));
out.println(response.getHeader("line_two"));
out.println(response.getHeader("line_three"));
out.println(response.getHeader("line_four"));
out.close();
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
line_number = Integer.parseInt(request.getHeader("line_number"));
file_reader.setLineNumber(line_number);
response.addHeader("line_one", file_reader.readLine());
file_reader.setLineNumber(line_number + 1);
response.addHeader("line_two", file_reader.readLine());
file_reader.setLineNumber(line_number + 700);
response.addHeader("line_three", file_reader.readLine());
file_reader.setLineNumber(line_number + 701);
response.addHeader("line_four", file_reader.readLine());
}
Basically it takes an integer sent from the iPhone via NSURLConnection in an NSURLRequest and returns 4 lines from a text file. The lines should be the line number of the integer received, integer + 1, integer + 700 and integer + 701. Yet when I send the request the servlet sends lines 1, 2, 3 and 4 back. If I stop the iPhone app and restart it the servlet then sends lines 5, 6, 7 and 8 back. Yet I was sure that the setLineNumber() method was meant to explicitly set the line number in the file input before reading it.
I have hard coded the number 1 into the iPhone app for testing so that is not a problem and checked that the servlet is receiving the correct number on the server side. Does anyone have any idea what could be happening?