Hello,
as a newbie in Ruby I'am playing with WEBrick.
Writing my own Servlet, derived from AbstractServlet class I can't get the query from URI. The servlet is:
class HelloServlet < WEBrick::HTTPServlet::AbstractServlet
def do_GET(req, res)
res['Content-Type'] = "text/html"
res.body << "<HTML>Hello!<P>#{show_req(req)}</HTML>"
end
def show_req(req)
"<DIV><H2>HTTP Request:</H2>" +
"<TABLE>" +
"<TR><TD>Request_URI</TD><TD>#{req.request_uri}</TD></TR>" +
"<TR><TD>Path Info</TD><TD>#{req.path_info}</TD></TR>" +
"<TR><TD>Request Line</TD><TD>#{req.request_line}</TD></TR>" +
"<TR><TD>Query</TD><TD>#{req.query}</TD></TR>" +
"<TR><TD>Query_String</TD><TD>#{req.query_string}</TD></TR>" +
"</TABLE>" +
"<HR>" +
"#{p req}" +
"</DIV>"
end
end
The servlet is mounted
erver.mount("/hello.html", HelloServlet)
But it works following. If I go to url
http://kvark:2001/hello.html
i got empty req.query_string, and req.request_uri is '/hello.html/'
notice the ending '/'.
Trying url with query:
http://kvark:2001/hello.html?vara=5
I got empty req.query_string, and req.request_uri is '/hello.html/' to.
it only works when i put '/' before '?' like this:
http://kvark:2001/hello.html/?vara=5
in this case I got req.query_string = 'vara=5'.
What I'am doing wrong?
--
Radek Hnilica <Radek at Hnilica dot CZ>
=======================================
No matter how far down the wrong road you've gone, turn back.
Turkish proverb