Re: Java Autopostback?

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 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());
else if(method.equals("POST"))
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 <>

Relevant Pages

  • Re: Got TCP/IP connection, but no file sharing!?
    ... No where can I find that having the Computer Browser Service ... and the server announces itself on the networking using the special ... and why doesn't a workgroup environment work the same ... server) generally acts as the master browser. ...
  • Re: =?ISO-8859-1?Q?Can=92t_see_a_compute?= =?ISO-8859-1?Q?r_in_the_network?=
    ... Find Computer Browser ... Find Server ... Find Workstation ... CONFIG and Browser and Sharedaccess are RUNNING. ...
  • Re: After setting up the network
    ... Find Computer Browser ... Find Server ... PsService v2.20 - Service information and configuration utility ... CPSServ Comprehensive Networking Services V1.10 - PERRINS2 ...
  • Re: CUPS Server Error
    ... Server Identity ... > # Classification: the classification level of the server. ... the default language if not specified by the browser. ... determines whether the scheduler will allow new printers ...
  • Re: FreeBSD 5.1, Cups problem
    ... Server Identity ... > # Classification: the classification level of the server. ... the default language if not specified by the browser. ... > # not advertised but you can still see printers on other hosts. ...