# How to pass data in webrick servlets

**URL:** <https://www.ruby-forum.com/t/how-to-pass-data-in-webrick-servlets/158896>\
**Category:** Ruby\
**Created:** [January 29, 2009, 5:51am UTC](https://www.ruby-forum.com/t/how-to-pass-data-in-webrick-servlets/158896 "2009-01-29T05:51:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wrapster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/df705f/32.png) [@wrapster](https://www.ruby-forum.com/u/wrapster)\
**Post date:** [January 29, 2009, 5:51am UTC](https://www.ruby-forum.com/t/how-to-pass-data-in-webrick-servlets/158896/1 "2009-01-29T05:51:46Z")

</div>

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 ”

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{  
  
Name:  
  
  
}  
res[‘Content-Type’] = “text/html”  
end  
end

class Dataread \< HTTPServlet::AbstractServlet  
def do\_GET(req,res)  
res.body = %Q{  
  
Welcome   
   
_}  
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](http://webrick.org)

---

<div class="post-metadata">

**Author:** ![wrapster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/df705f/32.png) [@wrapster](https://www.ruby-forum.com/u/wrapster)\
**Post date:** [October 26, 2009, 12:22pm UTC](https://www.ruby-forum.com/t/how-to-pass-data-in-webrick-servlets/158896/2 "2009-10-26T12:22:44Z")

</div>

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 ”
> 
> 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{  
>   
> Name:  
>   
>   
> }  
> res[‘Content-Type’] = “text/html”  
> end  
> end
> 
> class Dataread \< HTTPServlet::AbstractServlet  
> def do\_GET(req,res)  
> res.body = %Q{  
>   
> Welcome   
>    
> _}  
> 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](http://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
