aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes being stuck at readLine() when reading HTTP request  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "being stuck at readLine() when reading HTTP request  " Watch "being stuck at readLine() when reading HTTP request  " New topic
Author

being stuck at readLine() when reading HTTP request

Tony suankularb
Greenhorn

Joined: Aug 10, 2009
Posts: 19
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

Joined: Aug 10, 2009
Posts: 19
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

Joined: Apr 04, 2009
Posts: 89
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

Joined: Aug 20, 2004
Posts: 14
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:-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: being stuck at readLine() when reading HTTP request