WEBrick default index page

Instead of using an index.html, index.rhtml, index.cgi, etc. as the
default page to load on localhost:[port], I was wondering if it was
possible to load a servlet instead (i.e. '/index'). I have looked at
the WEBrick source, but could not figure out how to do this (even like
trying to execute a request or response).

Any help would be greatly appreciated.

Hi,

mitchell a écrit :

Instead of using an index.html, index.rhtml, index.cgi, etc. as the
default page to load on localhost:[port], I was wondering if it was
possible to load a servlet instead (i.e. '/index'). I have looked at
the WEBrick source, but could not figure out how to do this (even like
trying to execute a request or response).

Any help would be greatly appreciated.

I am not sure I really understood what you want to do but I think you can do something like:

require 'webrick'

svr = WEBrick::HTTPServer.new(
   :Port => 8080,
   :BindAddress => 'localhost'
)

svr.mount_proc('/') { |req, res|
   res.body = "This is not the default index!"
   res['content-type'] = "text/plain"
}

trap("INT") { svr.shutdown }

svr.start

Or you can mount a servlet instead of a proc...

HTH

Ghislain

Thank you, that worked. I do remember trying that earlier, but
something else had broken so I forgot about it.