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 xrhsimopoih sete 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. ______________________________________________________________________ Table of Contents 1. Eisagwgh 1.1 Progenesterh Gnwsh 1.2 Ayto to Eggrafo 1.3 To paketo 1.4 H Lista Taxydromeioy 2. Ry8mizontas to Diakomisth sas na trexei programmata Java CGI (me epejhghseis) 2.1 Apaithseis Systhmatos 2.2 Epipros8eto Logismiko Java CGI 2.3 3epaketarontas ton phgaio kwdika 2.4 Apofasiste gia tis politikes topikwn diadromwn sas 2.5 Elegxontas thn egkatastash sas 3. Ry8mizontas ton Diakomisth sas na trexei programmata Java CGI (o suntomos tropos) 4. Ektelwntas ena programma Java CGI 4.1 Empodia sto trejimo programmatwn Java katw apo to montelo CGI 4.1.1 Den mporeite na trejete programmata Java opws ta kanonika ektelesima. 4.1.2 H Java den exei genikh prosbash sto periballon. 4.2 3epernwntas problhmata sto trejimo programmatwn Java CGI 4.2.1 To java.cgi script 4.2.2 Kalwntas to java.cgi apo mia forma HTML 5. Xrhsimopoiwntas tis Java CGI Klaseis 5.1 CGI 5.1.1 Suntajh klashs 5.1.2 Perigrafh klashs 5.1.3 Perilhch melwn 5.1.4 Deite epishs 5.1.5 CGI() 5.1.6 getNames() 5.1.7 getValue() 5.2 CGI[lowbar]Test 5.2.1 Perilhch melwn 5.2.2 Deite epishs 5.2.3 main() 5.3 Email 5.3.1 Suntajh Klashs 5.3.2 Perigrafh klashs 5.3.3 Perilhch melwn 5.3.4 Deite epishs 5.3.5 Email() 5.3.6 send() 5.3.7 sendTo() 5.3.8 subject() 5.4 Email[lowbar]Test 5.4.1 Perilhch melwn 5.4.2 Deite epishs 5.4.3 main() 5.5 HTML 5.5.1 Suntajh klashs 5.5.2 Perigrafh klashs 5.5.3 Perilhch melwn 5.5.4 Deite epishs 5.5.5 HTML() 5.5.6 author() 5.5.7 definitionList() 5.5.8 definitionListTerm() 5.5.9 endList() 5.5.10 listItem() 5.5.11 send() 5.5.12 title() 5.6 HTML[lowbar]Test 5.6.1 Perilhch melwn 5.6.2 Deite epishs 5.6.3 main() 5.7 Text 5.7.1 Suntajh klashs 5.7.2 Perigrafh klashs 5.7.3 Perilhch melwn 5.7.4 Deite epishs 5.7.5 add() 5.7.6 addLineBreak() 5.7.7 addParagraph() 6. Mellontika Sxedia 7. Allages 7.1 Allages apo thn 0.4 sthn 0.5 7.2 Allages apo thn 0.3 sthn 0.4 7.3 Allages apo thn 0.2 sthn 0.3 7.4 Allages apo thn 0.1 sthn 0.2 ______________________________________________________________________ 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 ``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 ``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 - 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 ``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: