WEBrick & forms using post

J

James McCarthy

Im trying to write a webrick servlet to process a html form.
Im using the post method to send, NOT get (in the html form).
I have require 'cgi' in my servlet.
But I keep getting:

Method not allowed
unsupported method 'post'

Any ways to get around this or am I doing something wrong?
 
Y

Yohanes Santoso

James McCarthy said:
Im trying to write a webrick servlet to process a html form.
Im using the post method to send, NOT get (in the html form).
I have require 'cgi' in my servlet.
But I keep getting:

Method not allowed
unsupported method 'post'

Any ways to get around this or am I doing something wrong?

A WEBrick servlet is not a CGI, so, doing require 'cgi' is just a
gratuitous exercise, unless you want to use some of cgi's convenience
methods like CGI::escape, unescape, parse, etc.

A servlet accepts method POST if it has a method do_POST(request,
response):

E.g.:

class FooServlet < HTTPServlet::AbstractServlet
def do_POST(req, resp)
resp['content-type'] = 'text/plain'
resp.body << "You posted the following content:\n"
resp.body << req.body
end
end

YS.
 
J

James McCarthy

cheers, exactly what I was looking for.

A servlet accepts method POST if it has a method do_POST(request,
response):

E.g.:

class FooServlet < HTTPServlet::AbstractServlet
def do_POST(req, resp)
resp['content-type'] =3D 'text/plain'
resp.body << "You posted the following content:\n"
resp.body << req.body
end
end

YS.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top