【发布时间】:2017-04-04 06:15:52
【问题描述】:
当我运行 WEBrick 服务器实例并将浏览器指向 localhost:2000/so_question 时,服务器会抛出以下错误: 一世。错误 /some_image.jpg 未找到。 ii.错误 /jquery.min.js 未找到。
示例代码:
require 'webrick'; include WEBrick
s = HTTPServer.new Port: 2000
class SoQuestion < HTTPServlet::AbstractServlet
def do_GET req, resp
resp.status = 200
resp['Content-Type'] = 'text/html'
resp.body = prep_body
end
def prep_body
body = %(
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
)
body << '<p>Hello, world!</p>'
body << "<img src='some_image.jpg'>"
body << "<script src='jquery.min.js'></script>"
body << '</body></html>'
end
end
s.mount '/so_question', SoQuestion
trap('INT'){s.shutdown}
s.start
如何解决这些错误?请建议一个纯 Ruby 解决方案(没有宝石,请)。
谢谢。
【问题讨论】: