This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

being stuck at readLine() when reading HTTP request

 
Tony suankularb
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[])
 
Colm Dickson
Ranch Hand
Posts: 89
  • 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
 
Michael Parmeley
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:-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic