Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple Web Server  RSS feed

 
nikos sokaf
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to make a simple web server.
I finally make a succesfull conection an server by a browser and the handling of GET methods works perfectlly!
When i put on a browser http://localhost:80 i take my 'index.html' that i wanna take...
All these are good until now...
I want to develop more my simply server. Until now GET method works.
I don't Know how to handle POST or PUT method of HTTP 1.0...Or java beans on server side...ON SERVER SIDE!
I tried a lot but something is missing...I can't find it.
How can i take the values that client/browser send to the server?
I think that something like that is simple but , I am not experinced in WEB SERVICES with java...
Please give me a tip! Or where should i check for furthere instructions.
At SUN's site found nothing.Maybe i am searching at the wrong places.
Thanks a lot for your help, if any!!!
nikos sokaf at: nsalonis@yahoo.gr
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it suits your temperament, you can learn a lot by sending a post to your server and observing what comes in. Make an HTML page with a form holding a variety of buttons, check boxes, text areas, and so on and see what happens. Make your server read a line or a character at a time from the input and dump it all to the console.
I built such a thing last year. I spent some time on Google looking for HTML header definitions. That's where most of the good stuff comes in.
If you want to handle uploaded files, look at the OReilly upload servlet here: http://www.servlets.com/cos/index.html. You see it referenced often, but if you look at the code you may find it not the prettiest OO stuff, maybe a translation from C or something. I wrote my own since I was not in a servlet environment - and you won't be either since you're writing your own server.
And you can just read code. Google for java web server and you'll surely find a few. Lemme know if you get into particular problems. Have fun!
 
Samuel Jackson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd recommend reading RFC 2616 for information about how http works. It is well worth it.
Basically, a http request consists of the method line, headers, CRLF CRLF and the body, followed by CRLF CRLF. For a POST or PUT, something like this:
PUT /resource/name HTTP 1.1
Host: example.com
Date: <http date>CRLF
CRLF
entity body as being put.....CRLF
CRLF

where CRLF is carriage return + linefeed ascii characters
--------------------
Fluidlogic™
 
nikos sokaf
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Samuel Jackson:
I'd recommend reading RFC 2616 for information about how http works. It is well worth it.
Thanxx for your help , i will check your instructions and i will post the results!Thanxx again
Fluidlogic™

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!