J
JK
Hi All,
I am playing with Webrick and I tried to change a little the example given
with the packet but when I fill a html form and send it the fields values
are empty (using GET method, Webrick doesn't accept POST method). How to
fix it?
Thank you!
jilani
#!/usr/local/bin/ruby
require 'webrick'
include WEBrick
s = HTTPServer.newPort => 2000, ocumentRoot => "/xitami/webpages")
class HelloServlet < HTTPServlet::AbstractServlet
def do_GET(req, res)
name = req['fname']
email = req['email']
st = "<HTML>Hello #{fname} -- #{email} </HTML>"
res['Content-Type'] = "text/html"
res.body = st
end
end
s.mount("/hello", HelloServlet)
# HTTPServer#mount_proc(path){|req, res| ...}
# You can mount also a block by `mount_proc'.
# This block is called when GET or POST.
s.mount_proc("/hello/again"){|req, res|
res.body = "<HTML>hello (again)</HTML>"
res['Content-Type'] = "text/html"
}
trap("INT"){ s.shutdown }
s.start
it gives only "hello -- " as answer.
ps.
When I run the servlet, I get a warning:
"WARN TCPServer Error: Address family not supported by protocol - socket
(2)"
Everything under Linux Slackware 9.0 and Ruby 1.8.0
I am playing with Webrick and I tried to change a little the example given
with the packet but when I fill a html form and send it the fields values
are empty (using GET method, Webrick doesn't accept POST method). How to
fix it?
Thank you!
jilani
#!/usr/local/bin/ruby
require 'webrick'
include WEBrick
s = HTTPServer.newPort => 2000, ocumentRoot => "/xitami/webpages")
class HelloServlet < HTTPServlet::AbstractServlet
def do_GET(req, res)
name = req['fname']
email = req['email']
st = "<HTML>Hello #{fname} -- #{email} </HTML>"
res['Content-Type'] = "text/html"
res.body = st
end
end
s.mount("/hello", HelloServlet)
# HTTPServer#mount_proc(path){|req, res| ...}
# You can mount also a block by `mount_proc'.
# This block is called when GET or POST.
s.mount_proc("/hello/again"){|req, res|
res.body = "<HTML>hello (again)</HTML>"
res['Content-Type'] = "text/html"
}
trap("INT"){ s.shutdown }
s.start
it gives only "hello -- " as answer.
ps.
When I run the servlet, I get a warning:
"WARN TCPServer Error: Address family not supported by protocol - socket
(2)"
Everything under Linux Slackware 9.0 and Ruby 1.8.0