WEBrick.rb --------->ruby文件内容
#WEBrick.rb
require 'webrick'
class MyServlet < WEBrick::HTTPServlet::AbstractServlet
def do_GET(request, response)
response.status = 200
response.content_type = "text/plain"
response.body = "Hello, earth! \n \n \t \t This is a plain web layout demo for WEBrick.\n \t \t \t \t \t \t \t \t201312301432 ccy."
end
end
server = WEBrick::HTTPServer.new(:Port => 8002)
server.mount "/", MyServlet
trap("INT"){ server.shutdown }
server.start
Terminal -----------> 命令行操作
ching@ching ~/Projects/L/Ruby $ ruby WEBrick.rb
[2013-12-30 14:53:27] INFO WEBrick 1.3.1
[2013-12-30 14:53:27] INFO ruby 1.9.3 (2012-04-20) [x86_64-linux]
[2013-12-30 14:53:27] WARN TCPServer Error: Address already in use - bind(2)
[2013-12-30 14:53:27] INFO WEBrick::HTTPServer#start: pid=4714 port=8002
...............
Chrome ------------->浏览器效果