About WEBrick

本文摘自: [url]http://anw.stikipad.com/ocean/show/WEBrick[/url]
WEBrick 是用 Ruby ��的 web server, 若有�_�l Web Service 需要也可以用, 但若�_�l web ��用程式, 你���用 Rails 比�^好.

  1. WEBrick::HTTPServer �� web server
  2. servlet class ��^承自 HTTPServlet::AbstractServlet
    
    require 'webrick' include WEBrick #a function stub to start WEBrick def start_WEBrick(config = {}) config.update(:Port => 2000) server = HTTPServer.new(config) yield server if block_given? ['INT', 'TERM'].each do |signal| trap(signal) { server.shutdown } end server.start end class HelloServlet < HTTPServlet::AbstractServlet def do_GET(req, res) res["content-type"] = "text/html; charset=UTF-8" res.body = %{ <html> <body> Hello World! </body> </html> } end alias do_POST do_GET end # start_WEBrick do |server| #servlet "/hello" server.mount("/hello", HelloServlet) end 
  3. ��俞嵴� [url]http://localhost:2000/hello[/url] 就可以看到�热�
  4. WEBrick 也可以�理�o�B html �W�, 利用�冉� HTTPServlet::FileHandler
    
    # start_WEBrick do |server| #document root "/" doc_root = File.join(Dir.pwd, 'htdocs') server.mount("/", HTTPServlet::FileHandler, doc_root, {:FancyIndexing => true}) end

你可能感兴趣的:(敏捷开发,Ruby,Rails,DSL,ror)