http://webrick.lighttpdphp.com
WEBrick 是用
Ruby ��的
web server, 若有�_�l
Web Service 需要也可以用
, 但若�_�l
web ��用程式
, 你���用
Rails 比�^好
.
1. WEBrick::HTTPServer ��
web server
2. servlet class ��^承自
HTTPServlet::AbstractServlet
3.
4. require ’webrick’
5. include WEBrick
6.
7. #a function stub to start WEBrick
8. def start_WEBrick(config = {})
9. config.update(:Port => 2000)
10.
11. server = HTTPServer.new(config)
12. yield server if block_given?
13.
14. ['INT', 'TERM'].each do |signal|
15. trap(signal) { server.shutdown }
16. end
17. server.start
18. end
19.
20. class HelloServlet < HTTPServlet::AbstractServlet
21. def do_GET(req, res)
22. res["content-type"] = ”text/html; charset=UTF-8″
23. res.body = %{
24. <html>
25. <body>
26. Hello World!
27. </body>
28. </html>
29. }
30. end
31.
32. alias do_POST do_GET
33. end
34.
35. #
36. start_WEBrick do |server|
37. #servlet ”/hello”
38. server.mount(“/hello”, HelloServlet)
39. end
40. ��俞嵴�
http://localhost:2000/hello 就可以看到�热�
41. WEBrick 也可以�理�o�B
html �W�
, 利用�冉�
HTTPServlet::FileHandler
42.
43. #
44. start_WEBrick do |server|
45. #document root ”/”
46. doc_root = File.join(Dir.pwd, ’htdocs’)
47. server.mount(“/”, HTTPServlet::FileHandler, doc_root, {:FancyIndexing => true})
end