Ellhniko Java CGI HOWTO

David H. Silber javacgi-document@orbits.com v0.5, 1 Dekembrioy 1998

Ayto to eggrafo HOWTO ejhgei pws na ry8misete to diakomisth sas wste na epitrepei programmata CGI grammena se Java kai pws na xrhsimopoihsete th Java sto na grafete programmata CGI. An kai ayta ta HOWTO eggrafa stoxeuoyn se xrhsh me to leitoyrgiko susthma Linux, ayto to sygkekrimeno den einai ejartwmeno apo th sygkekrimenh ekdosh toy Unix poy xrhsimopoieite.

Contents

1 Eisagwgh 3 1.1 Progenesterh Gnwsh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.2 Ayto to Eggrafo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.3 To paketo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.4 H Lista Taxydromeioy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2 Ry8mizontas to Diakomisth sas na trexei programmata Java CGI (me epejhghseis) 4 2.1 Apaithseis Systhmatos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2.2 Epipros8eto Logismiko Java CGI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2.3 3epaketarontas ton phgaio kwdika . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2.4 Apofasiste gia tis politikes topikwn diadromwn sas . . . . . . . . . . . . . . . . . . . . . . . . 5 2.5 Elegxontas thn egkatastash sas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

3 Ry8mizontas ton Diakomisth sas na trexei programmata Java CGI (o suntomos tropos) 5

4 Ektelwntas ena programma Java CGI 6

4.1 Empodia sto trejimo programmatwn Java katw apo to montelo CGI . . . . . . . . . . . . . . 6 4.1.1 Den mporeite na trejete programmata Java opws ta kanonika ektelesima. . . . . . . . 6 4.1.2 H Java den exei genikh prosbash sto periballon. . . . . . . . . . . . . . . . . . . . . . . 6

4.2 3epernwntas problhmata sto trejimo programmatwn Java CGI . . . . . . . . . . . . . . . . . 6 4.2.1 To java.cgi script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 4.2.2 Kalwntas to java.cgi apo mia forma HTML . . . . . . . . . . . . . . . . . . . . . . . . 6

5 Xrhsimopoiwntas tis Java CGI Klaseis 6

5.1 CGI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 5.1.1 Suntajh klashs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 5.1.2 Perigrafh klashs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 5.1.3 Perilhch melwn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 5.1.4 Deite epishs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 5.1.5 CGI() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 5.1.6 getNames() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 5.1.7 getValue() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

5.2 CGI Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 5.2.1 Perilhch melwn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 5.2.2 Deite epishs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 5.2.3 main() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

5.3 Email . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5.3.1 Suntajh Klashs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5.3.2 Perigrafh klashs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5.3.3 Perilhch melwn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5.3.4 Deite epishs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5.3.5 Email() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5.3.6 send() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5.3.7 sendTo() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 5.3.8 subject() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

5.4 Email Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 5.4.1 Perilhch melwn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 5.4.2 Deite epishs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 5.4.3 main() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

5.5 HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 5.5.1 Suntajh klashs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 5.5.2 Perigrafh klashs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 5.5.3 Perilhch melwn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 5.5.4 Deite epishs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 5.5.5 HTML() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 5.5.6 author() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 5.5.7 definitionList() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 5.5.8 definitionListTerm() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.5.9 endList() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.5.10 listItem() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.5.11 send() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 5.5.12 title() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

5.6 HTML Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 5.6.1 Perilhch melwn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 5.6.2 Deite epishs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 5.6.3 main() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 5.7 Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

5.7.1 Suntajh klashs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 5.7.2 Perigrafh klashs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 5.7.3 Perilhch melwn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 5.7.4 Deite epishs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 5.7.5 add() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 5.7.6 addLineBreak() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 5.7.7 addParagraph() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

6 Mellontika Sxedia 17

7 Allages 18 7.1 Allages apo thn 0.4 sthn 0.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 7.2 Allages apo thn 0.3 sthn 0.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 7.3 Allages apo thn 0.2 sthn 0.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 7.4 Allages apo thn 0.1 sthn 0.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

1 Eisagwgh

Ejaitias toy tropoy poy h Java einai sxediasmenh, o programmatisths den exei eukolh prosbash stis metablhtes periballontos toy systhmatos. Ejaitias toy tropoy poy einai ry8mismeno to Java Development Kit (JDK), einai anagkaio na xrhsimopoieite pollapla sumbola gia na kaleite ena programma, to opoio den kollaei kai polu kala me ton typiko tropo leitoyrgiwn me formes/CGI ths HTML. Yparxoyn tropoi antimetwpishs aytwn twn periorismwn, kai exw efarmosei enan apo aytous. Diabaste peraiterw gia leptomereies. Apo tote poy egraca thn prohgoumenh paragrafo to 1996, exoyn ginei polles allages sthn texnologia Java. Einai pi8anon pws mia kaluterh lush gia na trexete Java programmata sthn pleyra-toy-diakomisth, einai twra dia8esimh – isws na prepei na rijete mia matia sta servlets.

1.1 Progenesterh Gnwsh

Ypo8etw oti exete mia genikh gnwsh ths HTML kai twn ennoiwn CGI kai toylaxiston mia elaxisth gnwsh toy diakomisth HTTP sas. 8a prepei epishs na gnwrizete pws na programmatisete se Java, alliws polla apo ayta de 8a bgazoyn nohma.

1.2 Ayto to Eggrafo

H teleytaia ekdosh aytou toy eggrafoy mporei na diabastei sthn http://www.orbits.com/software/Java\

_CGI.html.

1.3 To paketo

H teleytaia ekdosh toy paketoy poy perigrafetai edw mporei na prospelastei mesw anwnymo FTP sto ftp:

//ftp.orbits.com/pub/software/java\_cgi-0.5.tgz. H dianomh toy paketoy periexei phgaio kwdika

SGML gia ayto to eggrafo.

To paketo dianemetai katw apo toys oroys ths GNU Biblio8hkhs Genikhs Adeias toy Koinou (Library General Public License). Ayto to eggrafo mporei na dianemh8ei katw apo toys oroys ths shmeiwshs pneymatikwn dikaiwmatwn twn Linux HOWTOs.

An xrhsimopoieite ayto to logismiko, parakalw kante kapoia anafora sthn http://www.orbits.com/ software/Java\_CGI.html, etsi wste kai alloi na mporoun na briskoyn tis klaseis Java CGI.

Den exw allo xrono gia na synthrw kai na yposthrizw ayto to paketo, opote ayth pi8anon na einai h teleytaia toy kykloforia. An kaneis ekei ejw einai arketa erwteymenos me ayto to logismiko wste na euxetai na analabei th synthrhsh toy, parakalw epikoinwnhste mazi moy sthn javacgi-document@orbits.com.

1.4 H Lista Taxydromeioy

Exw dhmioyrghsei mia lista majordomo wste na epitrepw an8rwpoys na boh8oun o enas ton allon, na lunoyn amoibaia ta problhmata toys egka8istwntas kai xrhsimopoiwntas ayto to logismiko. Steilte ena mhnyma sthn javacgi-request@orbits.com, perilambanontas th lejh subscribe.

2 Ry8mizontas to Diakomisth sas na trexei programmata Java CGI (me epejhghseis)

Ayto to tmhma 8a sas ka8odhghsei kata thn egkatastash toy paketoy moy Java CGI me af8ones epejhghseis etsi wste na gnwrizete poia 8a einai ta apotelesmata twn energeiwn sas. An aplws 8elete na egkatasthsete ta programmata kai den endiafereste ka8oloy gia ta giati kai gia poioys logoys, phgainete sthn 3 (Ry8mizontas ton Diakomisth sas na trexei programmata Java CGI (o suntomos tropos)).

2.1 Apaithseis Systhmatos

Ayto to logismiko 8a prepei na doyleuei se ka8e unix-like diakomisth istou poy exei egkatesthmeno to Java Development Kit. Egw to xrhsimopoiw se ena susthma Debian Linux poy trexei ton apache san daimona HTTP. An diapistwsete oti den trexei ston diko sas diakomisth, parakalw epikoinwnhste me th lista taxydromeioy. Deite th 1.4 (The Mailing List) gia leptomereies.

Dystyxws, o Java run-time diermhneyths fainetai na einai kati san fataoulas mnhmhs – isws na 8elete na rijete liga perissotera megabytes apo RAM ston ejyphrethth sas an 8a xrhsimopoieite polu programmata Java CGI.

2.2 Epipros8eto Logismiko Java CGI

To logismiko poy egraca gia na boh8hsei se ayto legetai Java CGI . Mporeite na to parete apo to ftp:

//ftp.orbits.com/pub/software/java\_cgi-0.5.tgz. (O ari8mos ekdoshs mporei na exei allajei).

2.3 3epaketarontas ton phgaio kwdika

Breite enan katalogo poy sas boleuei ston opoio 8a jepaketarete ayto to paketo. (An den exete akomh ena sta8ero topo na topo8eteite paketa, proteinw na xrhsimopoihsete ton /usr/local/src.) 3epaketarete th dianomh me ayth thn entolh:

gzip -dc java_cgi-0.5.tgz | tar -xvf -

3. Ry8mizontas ton Diakomisth sas na trexei programmata Java CGI (o suntomos tropos) 5

Ayth 8a dhmioyrghsei enan katalogo me onoma java cgi-0.5. Ekei mesa 8a breite ta arxeia poy anaferontai sto ypoloipo aytou toy eggrafoy. (An o ari8mos ekdoshs exei allajei, xrhsimopoihste tis odhgies poy briskontai sth dianomh poy katebasate).

2.4 Apofasiste gia tis politikes topikwn diadromwn sas

Prepei na apofasisete pou 8elete na zoyn ta Java CGI programmata sas. Genika, 8a 8elete na ta topo8ethsete se enan katalogo parallhla me ton cgi-bin katalogo sas. O dikos moy diakomisths apache htan ry8mismenos na xrhsimopoihsei ton /var/www/cgi-bin san ton cgi-bin katalogo, opote xrhsimopoiw ton /var/www/javacgi san ton katalogo poy topo8etw mesa ta Java CGI programmata. Pi8anws na mh 8elete na topo8ethsete ta Java CGI programmata sas mesa se enan apo toys yparxontes katalogoys CLASSPATH. Epejergasteite to Makefile wste na antikatoptrizetai h ru8mish toy systhmatos sas. Epibebaiwste oti exete prosbash ws xrhsths root kai trejte thn entolh make install. Ayth 8a metaglwttisei ta Java programmata, 8a tropopoihsei to java.cgi senario gia na tairiazei me to susthma sas kai 8a egkatasthsei ta programmata sta aparaithta merh. An 8elete thn HTML ekdosh ayths ths tekmhriwshs kai ena HTML test eggrafo epipleon, trejte thn entolh make all anti ayths.

2.5 Elegxontas thn egkatastash sas

Egkatesthmena apo th dianomh einai HTML eggrafa poy onomazontai javacgitest.html, javaemailtest.html kai javahtmltest.html. Ean ta egkatasthsate ola - all sto prohgoumeno meros, 8a einai ston katalogo poy ka8orisate gia WEBDIR sto Makefile. An den to kanate, mporeite na

trejete thn entolh make test gia na ta xtisete apo ta javacgitest.html-dist, javaemailtest.html-dist
kai javahtmltest.html-dist.

Otan eiste sigoyroi pws h egkatastash sas doyleuei swsta, isws na epi8ymeite na diagracete ta

CGI Test.class, Email Test.class kai HTML Test.class apo ton JAVACGI katalogo sas kai ta
javacgitest.html, javaemailtest.html kai javahtmltest.html apo ton WEBDIR katalogo sas afou

deixnoyn sto xrhsth plhrofories poy einai kanonika mono dia8esimes ston diakomisth.

3 Ry8mizontas ton Diakomisth sas na trexei programmata Java CGI (o suntomos tropos)

   • Parte to paketo Java CGI apo to ftp://ftp.orbits.com/pub/software/java\_cgi-0.5.tgz. (O

ari8mos ekdoshs mporei na exei allajei).

• 3epaketarete th dianomh me ayth thn entolh:

     gzip -dc java_cgi-0.5.tgz | tar -xvf -

(An o ari8mos ekdoshs exei allajei, xrhsimopoihste tis odhgies mesa apo ekeinh th dianomh apo ayto to shmeio kai ustera).

• Epejergasteite to Makefile poy 8a breite sto molis dhmioyrghmeno katalogo java cgi-0.5 wste na einai katallhlo gia to susthma sas.

• San root, trejte thn entolh make install. Ayth 8a metaglwttisei ta Java programmata, 8a efarmosei tis sygkekrimenes plhrofories sto susthma sas kai 8a egkatasthsei ta diafora arxeia. An 8elete thn HTML ekdosh ayths ths tekmhriwshs kai ena HTML test eggrafo, trejte thn entolh make all anti ayths.

• 8a prepei na eiste etoimoi na jekinhsete.

4 Ektelwntas ena programma Java CGI

4.1 Empodia sto trejimo programmatwn Java katw apo to montelo CGI

Yparxoyn duo kuria problhmata sto trejimo enos programmatos Java apo enan diakomisth istou:

4.1.1 Den mporeite na trejete programmata Java opws ta kanonika ektelesima.

Xreiazetai na trejete ton diermhnea Java run-time kai na parexete thn arxikh klash (programma gia na trejete) sth grammh entolwn. Me mia forma HTML, den yparxei kamia frontida gia na stelnete mia grammh entolwn ston diakomisth istou.

4.1.2 H Java den exei genikh prosbash sto periballon.

Ka8e metablhth periballontos poy 8a xreiastei apo to programma Java prepei na perastei me safhneia. Den yparxei kamia me8odos paromoia me th leitoyrgia ths C, getenv() .

4.2 3epernwntas problhmata sto trejimo programmatwn Java CGI

Gia na antimetwpisete ayta ta empodia, egraca ena CGI programma kelufoys poy parexei tis plhrofories poy xreiazontai apo ton Java diermhnea.

4.2.1 To java.cgi script

Ayto to senario kelufoys diaxeirizetai thn allhlepidrash metaju toy HTTP daimona kai toy programmatos Java CGI poy epi8ymeite na xrhsimopoihsete. Ejagei to onoma toy programmatos poy 8elete na trejete apo ta dedomena poy parexontai apo to diakomisth. Syllegei ola ta dedomena periballontos se ena proswrino arxeio. Ustera, trexei ton Java run-time diermhnea me to onoma toy arxeioy apo tis plhrofories periballontos kai to onoma toy programmatos poy proste8hke sth grammh-entolwn.

To java.cgi script diamorfw8hke kai egkatasta8hke sto 2.4 (Apofasiste gia tis politikes topikwn diadromwn sas).

4.2.2 Kalwntas to java.cgi apo mia forma HTML

Oi formes moy poy xrhsimopoioun programmata Java CGI ka8orizoyn mia energeia formas opws akolou8ws:

<form action="/cgi-bin/java.cgi/CGI_Test" method="POST">

Opoy /cgi-bin/ einai o topikos sas CGI binary katalogos, java.cgi einai to Java front-end poy mas epitrepei na trexoyme programmata Java ston isto kai to CGI Test einai ena paradeigma onomatos programmatos Java gia na trejete.

5 Xrhsimopoiwntas tis Java CGI Klaseis

Yparxoyn pros to paron treis kuries klaseis poy yposthrizontai – 5.1 (CGI), 5.3 (Email) kai 5.5 (HTML). Skeftomai na pros8esw klaseis gia na antimetwpisw ta MIME-diamorfwmena eisagomena (input) kai ejagomena (output) – MIMEin & MIMEout, antistoixa.

Yparxoyn epishs merikes support kai test klaseis. 5.2 (CGI Test), 5.4 (Email Test) kai 5.4 (HTML Test) skopeuoyn na xrhsimopoih8oun gia na elegjoyn thn egkatastash sas. Mporoun epishs na xrhsimopoih8oun san ena shmeio-ekkinhshs gia ta dika sas programmata Java poy xrhsimopoioun ayth th biblio8hkh klasewn. H 5.7 (Text) klash einai h yperklash kai gia tis duo klaseis, thn Email kai thn HTML.

5.1 CGI

5.1.1 Suntajh klashs

public class CGI

5.1.2 Perigrafh klashs

H CGI klash krataei tis “CGI Plhrofories” – Metablhtes periballontos apo ton diakomisth istou kai to onoma/timh poy stelnontai apo mia forma otan h submit energeia einai epilegmenh. Oles oi plhrofories apo8hkeuontai se ena Properties antikeimeno klashs.

Ayth h klash einai sto paketo “Orbits.net”.

5.1.3 Perilhch melwn

CGI() // Kataskeyasths.

getNames() // Pairnei th lista onomatwn.

getValue() // Pairnei thn timh formas kata prosdiorismeno onoma.

5.1.4 Deite epishs

CGI Test.

5.1.5 CGI()

Purpose Kataskeyazei ena antikeimeno poy periexei ta dia8esima CGI dedomena.

Syntax

     public CGI()

Description Otan kataskeyazetai ena antikeimeno CGI, oles oi dia8esimes CGI plhrofories anarrofountai se apo8hkh topika sto neo antikeimeno.

5.1.6 getNames()

Purpose Kanei lista twn onomatwn poy einai orismenes gia na exoyn antistoixes times.

Syntax

     public Enumeration getKeys ()

Description

Parexei thn plhrh lista twn onomatwn gia ta opoia antistoixes times einai orismenes. Returns

Mia Enumeration olwn twn orismenwn onomatwn.

5.1.7 getValue()

Purpose

Epanakta thn value sysxetismenh me to name poy exei oristei. Syntax

     public String getValue ( String name )

Description Ayth h me8odos parexei th antistoixia metaju twn names kai values poy stelnontai apo mia HTML forma.

Parametros

name To kleidi kata to opoio oi times epilegontai.

Returns Ena String poy perilambanei thn timh.

5.2 CGI Test

Ayth h klash parexei ena paradeigma toy pws na xrhsimopoieite thn klash CGI kai ena programma elegxoy poy mporei na xrhsimopoih8ei gia na epibebaiwsei oti to paketo Java CGI leitoyrgei swsta.

5.2.1 Perilhch melwn

main() // Programma main().

5.2.2 Deite epishs

CGI.

5.2.3 main()

Purpose

Parexei mia main() me8odo. Syntax

     public static void main( String argv[] )

Description Ayto einai to shmeio kataxwrhshs gia ena programma CGI poy den kanei tipota allo apo to na anaferei mia lista me ola ta dia8esima onoma/timh zeygaria kai tis trexoyses times toys.

Parametros

argv[ ] Epixeirhmata perasmena sto programma apo to java.cgi script. Pros to paron axrhsimopoihth.

5.3 Email

5.3.1 Suntajh Klashs

public class Email extends Text

5.3.2 Perigrafh klashs Mhnumata sxhmatizontai me thn Text klash add*() me8odoys kai tis e-mail-sygkekrimenes me8odoys poy prosti8entai apo aythn thn klash. Otan oloklhrw8ei, to mhnyma stelnetai ston proorismo toy. Ayth h klash einai sto paketo “Orbits.net”.

5.3.3 Perilhch melwn Email() // Kataskeyasths. send() // Stelnei to e-mail mhnyma. sendTo() // Pros8etei enan proorismo gia to mhnyma. subject() // Ry8mizei to 8ema: gia to mhnyma.

5.3.4 Deite epishs

Email Test, Text.

5.3.5 Email() Purpose

Kataskeyazei ena antikeimeno to opoio 8a periexei ena email mhnyma. Syntax

     public Email()

Description

Ry8mizei ena keno mhnyma gia na oloklhrw8ei apo tis Email me8odoys. See Also

     Text.

5.3.6 send() Purpose

Stelnei to e-mail mhnyma.

Syntax

public void send ()

Description Ayth diamorfwnei kai stelnei to mhnyma. An kamia dieu8ynsh proorismou den exei ry8mistei, de lambanetai kamia energeia.

5.3.7 sendTo()

Purpose

Pros8etei enan proorismo gia ayto to mhnyma. Syntax

public String sendTo ( String address )

Description Pros8etei thn address sth lista proorismwn gia aythn thn me8odo. Den yparxei kanena orio ru8mishs ston ari8mo proorismwn poy ena e-mail mhnyma mporei na exei. Eimai sigoyros pws an sxhmatisete th lista arketa megalh, mporeite na yperbei te to mege8os ths listas parametrwn poy o Mail Transport Agent mporei na apodex8ei h na katanalwsete th mnhmh sas.

Parameter/

address Enas proorismos gia na steilete ayto to mhnyma.

5.3.8 subject()

Purpose

Stelnei to 8ema gia ayto to mhnyma. Syntax

public void subject ( String subject )

Description Ayth h me8odos ry8mizei to keimeno gia thn grammh Subject: toy e-mail. An klh8ei perissoteres apo mia fores, to teleytaio ry8mismeno 8ema einai ayto poy xrhsimopoieitai.

Parameter

subject To keimeno ths Subject: grammhs aytou toy mhnumatos.

5.4 Email Test

Ayth h klash parexei ena paradeigma toy pws na xrhsimopoieite thn Email klash kai ena test programma poy mporei na xrhsimopoih8ei gia na epibebaiwsei oti to Java CGI paketo leitoyrgei swsta.

5.4.1 Perilhch melwn main() // Programma main().

5.4.2 Deite epishs

Email.

5.4.3 main() Purpose

Parexei mia main() me8odo. Syntax

     public static void main( String argv[] )

Description Ayto einai to shmeio kataxwrhshs gia ena programma CGI poy anaferei mia lista me ola ta dia8esima onoma/timh zeygaria kai tis trexoyses times toys. Epishs, 8a steilei ayth th lista sthn ka8orismenh dieu8ynsh sthn Email metablhth.

Parametros

argv[ ] Epixeirhmata perniountai sto programma apo to java.cgi senario. Pros to paron axrhsimopoihta.

5.5 HTML

5.5.1 Suntajh klashs

public class HTML extends Text

5.5.2 Perigrafh klashs Mhnumata sxhmatizontai me thn Text klash add*() me8odoys kai tis HTML-sygkekrimenes me8odoys poy prosti8entai apo aythn thn klash. Otan oloklhrw8ei, to mhnyma stelnetai ston proorismo toy. Pros to paron, den yparxei elegxos sfalmatwn gia na epibebaiwsei oti oi me8odoi dhmioyrgias-listas xrhsimopoiountai se mia swsth seira, opote o programmatisths prepei na pairnei metra gia na mhn parabiasei thn HTML suntajh. Ayth h klash einai sto paketo “Orbits.net”.

5.5.3 Perilhch melwn HTML() // Kataskeyasths. author() // Ry8mizei to onoma toy syggrafea toy eggrafoy. definitionList() // 3ekina mia lista orismwn. definitionListTerm() // Pros8etei enan oro sth lista orismwn. endList() // Teleiwnei mia lista. listItem() // Pros8etei mia kataxwrish se mia lista. send() // Stelnei to HTML mhnyma. title() // Ry8mizei to keimeno gia ton titlo toy eggrafoy.

5.5.4 Deite epishs

HTML Test, Text.

5.5.5 HTML()

Purpose

Dhmioyrgei ena antikeimeno poy 8a periexei ena HTML mhnyma. Syntax

     public HTML()

Description

Ry8mizei ena keno mhnyma na symplhrw8ei apo tis HTML me8odoys. See Also

     Text.

5.5.6 author()

Purpose

Ry8mizei to onoma toy syggrafea toy eggrafoy. Syntax

     public void author ( String author )

Description

Ry8mizei to onoma toy syggrafea toy eggrafoy se author. Parameter/

author To keimeno poy prepei na xrhsimopoih8ei san o syggrafeas aytou toy mhnumatos.

See Also

     title().

5.5.7 definitionList()

Purpose

Arxizei mia lista orismwn. Syntax

     public void definitionList ()

Description Arxizei mia lista orismwn. H definition list einai mia lista eidikeymenh etsi wste ka8e kataxwrish sth lista einai enas term akoloy8oumenos apo to text orismwn gia ayton ton oro. H arxh mias listas orismwn 8a prepei na akoloy8eitai apo toylaxiston) ena oros/keimeno zeygari kai mia klhsh sthn endList() me8odo. Shmeiwste pws, pros to paron, oi listes den mporoun na einai fwliasmenes (nested) h mia mesa sthn allh.

See Also

definitionListTerm(), endList(), listItem().

5.5.8 definitionListTerm()

Purpose

Pros8etei enan oro sth lista orismwn. Syntax

public void definitionListTerm ()

Description Pros8etei enan oro sth lista orismwn. To keimeno gia to kommati toy oroy ths trexoysas kataxwrhshs listas 8a prepei na episynaptetai sto mhnyma afou h me8odos aytou kaleitai kai prin mia antistoixh listItem me8odos kaleitai.

See Also

definitionList(), listItem().

5.5.9 endList()

Purpose

Teleiwnei mia lista. Syntax

public void endList ()

Description Teleiwnei mia lista. Ayth h me8odos kleinei mia lista. Shmeiwste oti, pros to paron, oi listes den mporoun na einai fwliasmenes (nested), h mia mesa sthn allh.

See Also

definitionList().

5.5.10 listItem()

Purpose

Pros8etei mia kataxwrhsh se mia lista. Syntax

public void listItem ()

public void listItem ( String item )
public boolean listItem ( String term, String item )

Description Pros8etei mia kataxwrhsh se mia lista. An h prwth forma xrhsimopoieitai, to keimeno gia thn trexwn antikeimeno listas 8a prepei na episynaptetai sto mhnyma afou h me8odos ayth kaleitai kai prin alles me8odoi listas kalountai. Sthn deuterh kai trith forma, to item keimeno prosdiorizetai san mia parametros sth me8odo anti na (h epipros8etws sto na) episynaptetai sto mhnyma. H trith forma einai eidikh stis listes orismwn kai parexei kai ton oro kai toy orismo ths kataxwrhshs listas.

Parameters

item

To keimeno ayths ths kataxwrhshs listas. term

To keimeno ayths ths listas orismwn toy kommatiou toy oroy kataxwrhshs.

See Also

definitionList(), definitionListTerm(), endList().

5.5.11 send()

Purpose

Stelnei to HTML mhnyma. Syntax

public void send ()

Description Stelnei to HTML mhnyma.

5.5.12 title()

Purpose

Ry8mizei to keimeno gia ton titlo eggrafoy. Syntax

public void title ( String title )

Description

Ry8mizei to keimeno gia ton titlo eggrafoy. Parameter

title

To keimeno aytou toy titloy toy mhnumatos.

See Also

author().

5.6 HTML Test

Ayth h klash parexei ena paradeigma toy pws na xrhsimopoieite thn HTML klash kai ena test programma poy mporei na xrhsimopoih8ei gia na epibebaiwsei oti to paketo Java CGI leitoyrgei swsta. 5.6.1 Perilhch melwn main() // Programma main(). 5.6.2 Deite epishs

HTML.

5.6.3 main() Purpose

Parexei mia main() me8odo. Syntax

     public static void main( String argv[] )

Description Ayto einai to shmeio kataxwrhshs gia ena programma CGI poy epistrefei mia lista twn dia8esimwn onoma/timh zeygariwn se ena HTML eggrafo, me to ka8e onoma/timh zeygari na apeikonizetai se ena stoixeio listas orismwn.

Parametros

argv[ ] Epixeirhmata perasmena sto programma apo to java.cgi senario. Pros to paron de xrhsimopoiountai.

5.7 Text

5.7.1 Suntajh klashs

public abstract class Text

5.7.2 Perigrafh klashs H klash einai h yperklash twn Email kai HTML klasewn. Mhnumata xtizontai me tis me8odoys se aythn thn klash kai symplhrwnetai kai diamorfwnetai me tis me8odoys se ypoklaseis. Ayth h klash einai sto paketo “Orbits.text”. 5.7.3 Perilhch melwn Text() // Kataskeyasths. add() // Pros8etei keimeno se ayto to antikeimeno. addLineBreak() // Pros8etei mia diakoph grammhs. addParagraph() // Pros8etei mia diakoph paragrafoy.

5.7.4 Deite epishs

Email, HTML.

5.7.5 add()

Purpose

Pros8etei keimeno se ayto to antikeimeno. Syntax

     public void add ( char addition )
     public void add ( String addition )
     public void add ( StringBuffer addition )

Description

Pros8etei addition sta periexomena aytou toy antikeimenoy keimenoy. Parameter

addition Keimeno poy prepei na proste8ei sto antikeimeno keimenoy

See Also

     addLineBreak(), addParagraph().

5.7.6 addLineBreak()

Purpose

Anagkazei mia diakoph grammhs se ayto to shmeio sto keimeno. Syntax

     public void addLineBreak ()

Description

Pros8etei mia diakoph grammhs sto keimeno sto trexon shmeio. See Also

     add(), addParagraph().

5.7.7 addParagraph()

Purpose

Arxizei mia nea paragrafo. Syntax

public void add ()

Description

Arxizei mia nea paragrafo se ayto to shmeio sth roh keimenoy. See Also

add(), addLineBreak().

6 Mellontika Sxedia

• Pros8hkh sthn Email klash:

Email( int capacity )

Xrhsimopoieitai otan gnwrizoyme poso xwro to mhnyma 8a xreiastei na exei paraxwrhmeno. sendTo( String [ address )]

Pros8etei mia lista prwtarxikwn proorismwn sto e-mail mhnyma. sendCc( String address )

Pros8etei ena Carbon-Copy proorismo sto e-mail mhnyma. sendCc( String [ address )]

Pros8etei mia lista apo Carbon-Copy proorismous sto e-mail mhnyma. sendBcc( String address )

Pros8etei ena Blind Carbon-Copy proorismo sto e-mail mhnyma. sendBcc( String [ address )]

Pros8etei mia lista apo Blind Carbon-Copy proorismous sto e-mail mhnyma.

• Pros8hkh sthn HTML klash:

HTML( int capacity )

Xrhsimopoieitai otan gnwrizoyme poso xwro to mhnyma

8a xreiastei na exei paraxwrhmeno. public void unorderedList()

Arxizei mia mh tajinomhmenh lista. public void orderedList()

Arxizei mia tajinomhmenh lista. public void directoryList()

Arxizei mia lista katalogwn. public void menuList()

Arxizei mia lista menou. void anchor( String anchorName )

Prosdiorizei ena anchor. void link( String url, String text )

Prosdiorizei enan desmo. void applet( String url, String altText )

Prosdiorizei enan desmo applet.

• Epitrepei fwliasmenes (nested) HTML listes.

• Pros8hkh kwdika elegxoy sfalmatwn gia na epiballei swsth tajinomhsh ths HTML listas kwdikwn diamorfwshs.

• H topo8esia toy arxeioy twn dedomenwn periballontos 8a prepei na einai diamorfwsimo apo to

  Makefile.

• Apallagh apo to ceutika adeio onoma/timh zeygari poy emfanizetai mesa sth lista otan antimetwpizoyme thn GET me8odo ths metaforas dedomenwn.

• Skech gia na exoyme to CGI na ektelei thn java.util.Enumeration epifaneia gia na parexei epityxws onomata metablhtwn.

• Pros8hkh mias Test klashs, poy 8a xrhsimopoiouse ka8e me8odo se ayto to paketo.

• Tekmhriwsh pws oi CGI Test, Email Test kai HTML Test xtisthkan h mia panw sthn allh gia na parexoyn ayjanomenoys elegxoys gia skopous eksfalmatwshs.

• Tekmhriwsh pws h Test xrhsimopoiei ka8e xarakthristiko dia8esimo se ayto to paketo.

7 Allages

7.1 Allages apo thn 0.4 sthn 0.5

• Allaxthke h tekmhriwsh kai ta sxolia gia na antikatoptrizetai h telikh fush ayths ths kykloforias.

7.2 Allages apo thn 0.3 sthn 0.4

• Ensarkw8hke h HTML klash gia na parexei elaxisth leitoyrgikothta.

• Grafthke h HTML Test klash kai to javahtmltest.html-dist.

• Proste8hkan oi HTML me8odoi gia na antimetwpistei mia lista orismwn.

7.3 Allages apo thn 0.2 sthn 0.3

• Proste8hkan oi Text kai Email klaseis. H HTML epishs proste8hke, alla htan mono ena apokomma se ayto to shmeio.

• Topo8eth8hkan oi diafores klaseis se paketa. Oi kuries klaseis einai sto Orbits.net.*, h klash yposthri-

  jhs Text einai sto Orbits.text.Text.

• Allaxthke to CGItest se CGI Test.

• Proste8hke h Email Test klash.

7.4 Allages apo thn 0.1 sthn 0.2

• Oi metablhtes periballontos topo8etountai se ena proswrino arxeio anti na einai stoibagmenes sth grammh-entolwn toy Java diermhnea . H CGI klash kai to java.cgi eprepe na tropopoih8oun.

• To javacgitest.html eggrafo ginetai meros ths dianomhs.

• Ta arxeia keimenoy poy tropopoiountai apo thn make kata thn egkatastash parexontai me onomata poy teleiwnoyn se -dist.