Sponsored Content
Top Forums Web Development how to pass data in webrick sevelts? please help Post 302281442 by wrapster on Thursday 29th of January 2009 12:02:28 AM
Old 01-29-2009
how to pass data in webrick sevelts? please help

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
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

pf not working properly even with only "pass in all" and "pass out all" rules

i have two rules in my pf.conf file, "pass in all" and "pass out all" i was having issues with getting pf working to begin with, so i went with starting from nothing and working on up. i have an ultrasparc ultra1 200e, with an added 4-port fast ethernet sbus card, running "3.4 GENERIC#85... (4 Replies)
Discussion started by: xyyz
4 Replies

2. UNIX for Dummies Questions & Answers

Howto capture data from rs232port andpull data into oracle database-9i automatically

Hi, i willbe very much grateful to u if u help me out.. if i simply connect pbx machine to printer by serial port RS232 then we find this view: But i want to capture this data into database automatically when the pbx is running.The table in database will contain similar to this view inthe... (1 Reply)
Discussion started by: boss
1 Replies

3. Shell Programming and Scripting

pass curls progress/status data to a file

hello hackers again. please help me out once again. i have a script which executes CURL to fetch a file from the web and instantly outputs the files content to STDOUT. now my question - can i somehow write the progress-status to a file? so that curl acts silently (-s) and only puts... (0 Replies)
Discussion started by: scarfake
0 Replies

4. Programming

issues regarding <frameset> usage in webrick servlets, pls help

Hi all, Ive been trying to execute <frameset> tags within webrick servlets.. But when the server is started i get erreneous o/p ... The html code if executed individually runs flawlesswelly but inside the servlet it cribs... Could anyone please help me out? (0 Replies)
Discussion started by: wrapster
0 Replies

5. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

6. Shell Programming and Scripting

How to pass data from server (CGI script) to client (html page)

Hi I know how to pass data from client side (html file) to server using CGI script (POST method). I also know how to re-create the html page from server side after receiving the data (using printf). However I want to write static pages on client side (only the structure), and only to pass... (0 Replies)
Discussion started by: naamabm
0 Replies

7. Shell Programming and Scripting

How i can obtain differents data on a single pass?

#!/bin/bash for i in `ls -c1 /usr/share/applications` do #name=`cat /usr/share/applications/$i | grep ^Name= | cut -d = -f2` #categories=`cat /usr/share/applications/$i | grep ^Categories= | sed 's/;/=/g' | cut -d = -f2` name=$(grep ^Name= /usr/share/applications/$i | cut -d = -f2)... (12 Replies)
Discussion started by: alexscript
12 Replies

8. Shell Programming and Scripting

Converting variable space width data into CSV data in bash

Hi All, I was wondering how I can convert each line in an input file where fields are separated by variable width spaces into a CSV file. Below is the scenario what I am looking for. My Input data in inputfile.txt 19 15657 15685 Sr2dReader 107.88 105.51... (4 Replies)
Discussion started by: vharsha
4 Replies

9. Shell Programming and Scripting

Pass some data from csv to xml file using shell/python

Hello gurus, I have a csv file with bunch of datas in each column. (see attached) Now I have an .xml file in the structure of below: ?xml version="1.0" ?> <component id="root" name="root"> <component id="system" name="system"> <param name="number_of_A" value="8"/> ... (5 Replies)
Discussion started by: Zam_1234
5 Replies

10. Web Development

Problems starting webserver (WEBRick) on Rails

Good afternoon: I need your help please: Im new at web applications and i started taking a Ruby on Rails course and as a part of the installations i followed the instructions given on page: http://railsapps.github.io/installrubyonrails-ubuntu.html I followed every step and id did not yield... (6 Replies)
Discussion started by: alexcol
6 Replies
Web::Simple::Application(3pm)				User Contributed Perl Documentation			     Web::Simple::Application(3pm)

NAME
Web::Simple::Application - A base class for your Web-Simple application DESCRIPTION
This is a base class for your Web::Simple application. You probably don't need to construct this class yourself, since Web::Simple does the 'heavy lifting' for you in that regards. METHODS
This class exposes the following public methods. default_config Merges with the "config" initializer to provide configuration information for your application. For example: sub default_config { ( title => 'Bloggery', posts_dir => $FindBin::Bin.'/posts', ); } Now, the "config" attribute of $self will be set to a HashRef containing keys 'title' and 'posts_dir'. The keys from default_config are merged into any config supplied, so if you construct your application like: MyWebSimpleApp::Web->new( config => { title => 'Spoon', environment => 'dev' } ) then "config" will contain: { title => 'Spoon', posts_dir => '/path/to/myapp/posts', environment => 'dev' } run_if_script The run_if_script method is designed to be used at the end of the script or .pm file where your application class is defined - for example: ## my_web_simple_app.pl #!/usr/bin/env perl use Web::Simple 'HelloWorld'; { package HelloWorld; sub dispatch_request { sub (GET) { [ 200, [ 'Content-type', 'text/plain' ], [ 'Hello world!' ] ] }, sub () { [ 405, [ 'Content-type', 'text/plain' ], [ 'Method not allowed' ] ] } } } HelloWorld->run_if_script; This returns a true value, so your file is now valid as a module - so require 'my_web_simple_app.pl'; my $hw = HelloWorld->new; will work fine (and you can rename it to lib/HelloWorld.pm later to make it a real use-able module). However, it detects if it's being run as a script (via testing $0) and if so attempts to do the right thing. If run under a CGI environment, your application will execute as a CGI. If run under a FastCGI environment, your application will execute as a FastCGI process (this works both for dynamic shared-hosting-style FastCGI and for apache FastCgiServer style setups). If run from the commandline with a URL path, it runs a GET request against that path - $ perl -Ilib examples/hello-world/hello-world.cgi / 200 OK Content-Type: text/plain Hello world! You can also provide a method name - $ perl -Ilib examples/hello-world/hello-world.cgi POST / 405 Method Not Allowed Content-Type: text/plain Method not allowed For a POST or PUT request, pairs on the command line will be treated as form variables. For any request, pairs on the command line ending in : are treated as headers, and 'Content:' will set the request body - $ ./myapp POST / Accept: text/html form_field_name form_field_value $ ./myapp POST / Content-Type: text/json Content: '{ "json": "here" }' The body of the response is sent to STDOUT and the headers to STDERR, so $ ./myapp GET / >index.html will generally do the right thing. Additionally, you can treat the file as though it were a standard PSGI application file (*.psgi). For example you can start up up with "plackup" plackup my_web_simple_app.pl or "starman" starman my_web_simple_app.pl to_psgi_app This method is called by "run_if_script" to create the PSGI app coderef for use via Plack and plackup. If you want to globally add middleware, you can override this method: use Web::Simple 'HelloWorld'; use Plack::Builder; { package HelloWorld; around 'to_psgi_app', sub { my ($orig, $self) = (shift, shift); my $app = $self->$orig(@_); builder { enable ...; ## whatever middleware you want $app; }; }; } This method can also be used to mount a Web::Simple application within a separate "*.psgi" file - use strictures 1; use Plack::Builder; use WSApp; use AnotherWSApp; builder { mount '/' => WSApp->to_psgi_app; mount '/another' => AnotherWSApp->to_psgi_app; }; This method can be called as a class method, in which case it implicitly calls ->new, or as an object method ... in which case it doesn't. run Used for running your application under stand-alone CGI and FCGI modes. I should document this more extensively but run_if_script will call it when you need it, so don't worry about it too much. run_test_request my $res = $app->run_test_request(GET => '/' => %headers); my $res = $app->run_test_request(POST => '/' => %headers_or_form); my $res = $app->run_test_request($http_request); Accepts either an HTTP::Request object or ($method, $path) and runs that request against the application, returning an HTTP::Response object. If the HTTP method is POST or PUT, then a series of pairs can be passed after this to create a form style message body. If you need to test an upload, then create an HTTP::Request object by hand or use the "POST" subroutine provided by HTTP::Request::Common. If pairs are passed where the key ends in :, it is instead treated as a headers, so: my $res = $app->run_test_request( POST => '/', 'Accept:' => 'text/html', some_form_key => 'value' ); will do what you expect. You can also pass a special key of Content: to set the request body: my $res = $app->run_test_request( POST => '/', 'Content-Type:' => 'text/json', 'Content:' => '{ "json": "here" }', ); AUTHORS
See Web::Simple for authors. COPYRIGHT AND LICENSE
See Web::Simple for the copyright and license. perl v5.14.2 2012-05-11 Web::Simple::Application(3pm)
All times are GMT -4. The time now is 05:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy