If you have CGI backgroung you know that exists 2 ways of calling these
programs. Using servlet is not diferent, you can call a servlet using a POST
method described bellow or using a GET, in these king of call the servlet
address and its parameters are joined into the URL and, like a URL, you this
servlet also in the Browser URL field.
Post method example:
<FORM NAME = "aTest" ACTION
="http://machine:port_number/servlets/servletName" METHOD="GET">
<PRE>
UserName: <INPUT TYPE = TEXT name = "Username"><P>
Password: <INPUT TYPE = PASSWORD name = "Password"><BR><BR>
</PRE>
<BR>
<INPUT TYPE = SUBMIT VALUE = "Done with Login">
<BR>
</FORM>
The effect of pressing the submit button is the call to the servlet using
the post method way. The parameter Username and Password are submmited along
with these call since they play a parameter role.
You must have a Web Server JSDK compliant, in other word, your web server
must support this Java API. If it's not possible you can use the
ServletRunner, a servlet container that comes with the JSDK that runs
independently from the web server. It's not the better way, it's not so
robust.
Talking about servlet now. You must extend the HTTPServlet class to capture
the call you have done in the HTML above. In this class and the ancestors
you will find three main methods you must know at prime: init, doPost and
doGet.
init(): when the first call to the servlet is made, the init methos is
invoked. You must initialize all the values shared by the servlet call. A
good exemple to you is the jdbc database connection used in other calls to
this same servlet. Depending on the database choosen you must configure the
connection slightly different (user, password, drivers, ...). I suggest you
first capture the information passed to the servlet and write it to a file
using stream (FileOutputStream).
doPost(): the servletName servlet you me invokeg as soon as you click in the
submit button in the HTML above. When it happens this methos will be called.
You can parse the parameter passed to the servlet as well as make the
appropriate calls to the database in order to insert the field is said.
doGet(): conceptually do the same. Using a different aproach already said.
Regards,
Marcelo Bezerra d'Amorim
ps. There's some exemples of use at www.javasoft.com
----- Original Message -----
From: Moloy Biswas <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, February 15, 2000 10:36 PM
Subject: Help required
> Hi Guys
>
> I have a table with 2 columns name and phone. Now I want a servlets
> which will be called from a browser where user will get to input these 2
> fields from the browser and the servlet will again take care of
> inserting the data inputted into the database.
>
> I am stuck here, can anybody help me with a sample code of the servlet
> where html code will also be embedded.
>
> I will be thankful to you forever for yor help.
>
> Thanks in advance
>
> Moloy
>
>
> --------------------------------------------------------------
> SREI INTERNATIONAL FINANCE LTD., CALCUTTA, INDIA
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html