This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

being stuck at readLine() when reading HTTP request  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my first assignment of Jsp and Servlet class. the professor want us to understand how Jsp and Servlet work by writing a web server. Anyway, I've have been stuck with this problem for a few day.

I'm writing a web server program, but not implementing the client, just write HTML page and use general browsers (e.g. IE, Firefox) to contact the server. A client's browser send requests(POST or GET) and the web server responds.

In case of POST method, parameters are in the body of HTTP request

Example

POST /login.jsp HTTP/1.1
Host: www.mysite.com
User-Agent: Mozilla/4.0
Content-Length: 27
Content-Type: application/x-www-form-urlencoded

userid=joe&password=guessme



here is my code




When a browser sent a POST request to the web server, the program printed only check point1, but not the value of params because the program is stuck at the line String params = in.readLine();

At that time, the client's browser was still waiting for the server. However, when I stoped the browser, the program immediately printed params


I don't really know what happened, but I doubt that after reading the blank line before the body, something's happened.
Any idea?

Thank you.

 
Tony suankularb
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Umm, I've known the problem. Because the body doesn't end with new line, it cannot use readLine(). Instead, use read(char[])
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I encountered something like that before and in my case it was that I'd read past the content in the reader and you need to get out the content you need before it moves past the data it holds


Colm
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying to use BufferedReader on data that doesn't end with a newline bites everyone at some point in time, so don't feel bad:-)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!