Re: Java Autopostback?
- From: "Vittorix" <vittorix@xxxxxxxxx>
- Date: Tue, 29 Jan 2008 21:38:35 -0600
Robert Larsen wrote:
I'm writing a web server in Java for html and servlets.I don't think the bug is in those four lines. What you need is a good
when the server receives a GET request, it works fine.
problem: when I use POST, the server program stops and the submit
button has to be clicked another time or the page has to be manually
refreshed (after that it works fine).
so, the program waits for the client to send a new signal/request.
The problem is caused by a in.readLine() statement:
if(method.equals("GET") && URI.contains("?"))
paraLine = URI.substring(URI.indexOf("?")+1, URI.length());
else if(method.equals("POST"))
paraLine = in.readLine(); // in the POST request, the
parameters are in the http request body
how to avoid that?
debugger and I recommend jSwat: http://jswat.sourceforge.net/
yes, it was, and I solved the problem using read() instead of readLine() in
this way:
else if(method.equals("POST"))
{ // POST method
int ch;
int len = Integer.parseInt((String)
headers.get("Content-Length")); // POST request Content-Length header
paraLine = "";
for(int i=1; i<=len; i++)
{
ch = in.read();
paraLine += (char) ch; // in the POST request,
the parameters are in the http request body
}
}
By the way, you can also pass GET-like parameters to a POST request:
POST somefile.php?hello=world HTTP/1.1
this is fun
--
ciao
Vittorix
.
- Follow-Ups:
- Re: Java Autopostback?
- From: Robert Larsen
- Re: Java Autopostback?
- References:
- Java Autopostback?
- From: Vittorix
- Re: Java Autopostback?
- From: Robert Larsen
- Java Autopostback?
- Prev by Date: How is Java typically invoked from HTML?
- Next by Date: Re: Java Autopostback?
- Previous by thread: Re: Java Autopostback?
- Next by thread: Re: Java Autopostback?
- Index(es):