Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

WEBrick servlet skeleton (See related posts)

// Skeleton code for a WEBrick servlet.

require 'webrick'
include WEBrick
class UberServlet < HTTPServlet::AbstractServlet

  def do_GET(req, res)
    id = req.query['id'] # Get GET/POST params like that.
    res['content-type'] = 'text/html'
    res.status = 200
    res.body = some_text
  end
  alias :do_POST :do_GET

end

# "Mount" the servlet.
server = HTTPServer.new(:Port => 1234)
server.mount('/some/path', UberServlet)

# Handle signals.
%w(INT TERM).each do |signal|
  trap(signal) { server.shutdown }
end

server.start

You need to create an account or log in to post comments to this site.


Click here to browse all 4858 code snippets

Related Posts