Re: Java Autopostback?
- From: dagon@xxxxxxxxx (Mark Rafn)
- Date: Mon, 28 Jan 2008 11:10:23 -0800
Vittorix <vittorix@xxxxxxxxx> wrote:
I'm writing a web server in Java for html and servlets.
In general, I'd recommend reusing one of the MANY choices already available.
Tomcat or Jetty are the ones I'd start with, but
http://java-source.net/open-source/web-servers lists plenty to choose from.
Writing one for your own education is fine, of course, but I'd recommend start
small, maybe static files and a subset of the servlet spec.
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).
Umm, you're mixing up client and server behavior. If you're going to write an
http server, do NOT use a browser as your primary test harness. Use a test
client that gives you control over content, and validates the return rather
than rendering it.
I'd probably use the Jakarta Commons HttpClient package, run from JUnit.
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());
paraLine = in.readLine(); // in the POST request, the parameters are
in the http request body
1) Fire up a command-line post utility and see what's really going on. Or
install LiveHTTPHeaders in firefox. It's very likely that you're assuming a
format that doesn't actually match what's transmitted. And it's equally
likely that the bug isn't in this snippet of code, but somewhere around it.
2) Using blocking buffered IO in a server like this is asking for trouble.
Even if you get it working correctly, you're setting yourself up for pain when
you encounter a browser that behaves incorrectly. You should read blocks of
data, and parse them as needed.
Mark Rafn dagon@xxxxxxxxx <http://www.dagon.net/>
- Java Autopostback?
- From: Vittorix
- Java Autopostback?