Hi all,
I am a newbie to servlet programming using webrick...
Was wondering how to accept data from a form and do necessary
processing..
To start with i wrote a sample servlet that accepts a name and prints
"welcome <name>"
But I do not know how to take this value from the form into the servlet
and print it out...
this is what i worte... can anyone please help me with this.
s = HTTPServer.new( :Port => 9000)
class TextServlet < HTTPServlet::AbstractServlet
def do_GET(req, res)
res.body = %Q{<html>
<form action = "text.rb">
Name:<input type = "text" name = "text1">
<input type = "submit">
</form>
</html>}
res['Content-Type'] = "text/html"
end
end
class Dataread < HTTPServlet::AbstractServlet
def do_GET(req,res)
res.body = %Q{<html>
<body>
Welcome <I dont know how to call it here>
</body>
</html>}
res['Content-Type'] = 'text/html'
end
end
trap("INT") {s.shutdown}
s.mount("/" , TextServlet)
s.mount("/text.rb", Dataread)
s.start
I am a total beginner to this , so please help me out....
Also if there is any resource online available do point me to it, apart
from webrick.org
on 2009-01-29 05:51
on 2009-10-26 12:22
Wrapster Aol wrote: > Hi all, > > I am a newbie to servlet programming using webrick... > Was wondering how to accept data from a form and do necessary > processing.. > To start with i wrote a sample servlet that accepts a name and prints > "welcome <name>" > > But I do not know how to take this value from the form into the servlet > and print it out... > this is what i worte... can anyone please help me with this. > > s = HTTPServer.new( :Port => 9000) > class TextServlet < HTTPServlet::AbstractServlet > def do_GET(req, res) > res.body = %Q{<html> > <form action = "text.rb"> > Name:<input type = "text" name = "text1"> > <input type = "submit"> > </form> > </html>} > res['Content-Type'] = "text/html" > end > end > > class Dataread < HTTPServlet::AbstractServlet > def do_GET(req,res) > res.body = %Q{<html> > <body> > Welcome <I dont know how to call it here> > </body> > </html>} > res['Content-Type'] = 'text/html' > end > end > > trap("INT") {s.shutdown} > s.mount("/" , TextServlet) > s.mount("/text.rb", Dataread) > s.start > > I am a total beginner to this , so please help me out.... > Also if there is any resource online available do point me to it, apart > from webrick.org Hi Wrapster, Forvive the late reply, but I only just joined up ;-) You could replace the text between your <>'s to #{req.query['text1']} Cheers, Brad
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.