Linux °æ (¾«»ªÇø)
·¢ÐÅÈË: netiscpu (˵²»Èç×ö), ÐÅÇø: Unix
±ê Ìâ: [CLDP]Javacgi-HOwto (ÖÐÎÄ)
·¢ÐÅÕ¾: ×Ï ¶¡ Ïã (Tue May 19 08:19:07 1998), תÐÅ
·¢ÐÅÈË: dfbb (ÕÔÎÞ¼É), ÐÅÇø: Linux
±ê Ìâ: [CLDP]Javacgi-HOwto
·¢ÐÅÕ¾: BBS ˮľÇ廪վ (Sat May 2 23:06:44 1998)
Java CGI HOWTO ÖÐÒë°æ
×÷Õß: David H. Silber dhs@orbits.com
ÒëÕß: C.W.Huang cwhuang@phys.ntu.edu.tw
v0.4, 18 November 1996. ·ÒëÈÕÆÚ: 21-25 August 1997
_________________________________________________________________
±¾ÎĽâÊÍÈçºÎÉ趨ÄãµÄËÅ·þÆ÷£¬Ê¹ÆäÄÜʹÓà Java À´Ð´ CGI ³Ìʽ£¬ÒÔ¼°ÈçºÎÓÃ
Java À´Ð´ CGI ³Ìʽ£®ËäÈ» HOWTO ÎļþµÄÄ¿µÄÊÇÓÃÔÚ Linux
×÷ҵϵͳÉÏ£¬µ«ÕâƪÌرðµÄÎÄÕÂÊÂʵÉÏÓëÌض¨°æ±¾µÄ UNIX ϵͳÎ޹أ®
_________________________________________________________________
1. ¼ò½é
1.1. Ô¤±¸ÖªÊ¶
1.2. Õâ·ÝÎļþ
1.3. ÈíÌåÌ×¼þ
1.4. ¹ã¸æÒ»ÏÂ
2. É趨ËÅ·þÆ÷ÒÔÖ´ÐÐ Java CGI ³Ìʽ (½âÊÍƪ)
2.1. ϵͳÐèÇó
2.2. Java CGI ¸¨ÖúÈíÌå
2.3. ½â¿ªÔʼµµ
2.4. ¾ö¶¨ÄãµÄ±¾µØĿ¼²ßÂÔ
2.5. ²âÊÔÄãµÄ°²×°
3. É趨ËÅ·þÆ÷ÒÔÖ´ÐÐ Java CGI ³Ìʽ (¼òÂÔƪ)
4. Ö´ÐÐÒ»¸ö Java CGI ³Ìʽ
4.1. ÒÔ CGI ģʽִÐÐ Java ³ÌʽµÄÕÏ°
4.2. Ö´ÐÐ Java CGI ½â¾öÎÊÌâ
5. ʹÓà Java CGI Àà±ð
5.1. CGI
5.2. CGI_Test
5.3. Email
5.4. Email_Test
5.5. HTML
5.6. HTML_Test
5.7. Text
6. δÀ´µÄ¼Æ»
7. °æ±¾Ð޸ļǼ
7.1. ÓÉ 0.3 µ½ 0.4 µÄÐÞ¸Ä
7.2. ÓÉ 0.2 µ½ 0.3 µÄÐÞ¸Ä
7.3. ÓÉ 0.1 µ½ 0.2 µÄÐÞ¸Ä
Java CGI HOWTO ÖÐÒë°æ : ¼ò½é
Previous: Java CGI HOWTO ÖÐÒë°æ
Next: É趨ËÅ·þÆ÷ÒÔÖ´ÐÐ Java CGI ³Ìʽ (½âÊÍƪ)
_________________________________________________________________
1. ¼ò½é
ÓÉì¶ Java µÄÉè¼Æ·½Ê½³ÌʽÉè¼ÆʦûÓмòÒ׵ķ½·¨¿ÉÒÔÈ¡µÃϵͳµÄ»·¾³±äÊý£®
ÓÉì¶ Java ·¢Õ¹¹¤¾ß (JDK)
½¨Á¢µÄ·½Ê½£¬ºô½ÐÒ»¸ö³Ìʽ±ØÐëʹÓöàÖرíáç(tokens)£¬ ÕâºÍ±ê×¼µÄ HTML
forms/CGI ÔË×÷·½Ê½²»Ò×ÅäºÏ£®
ÓÐһЩ°ì·¨¿ÉÒÔ¿Ë·þÕâЩÏÞÖÆ£¬¶øÎÒ¾Íʵ×÷ÁËÆäÖÐÒ»ÖÖ£®ÏêÇéÇë¼ûÏÂÊö£®
1.1. Ô¤±¸ÖªÊ¶
ÎÒ¼Ù¶¨ÄãÓÐ HTML Óë CGI ¸ÅÄîµÄÒ»°ã֪ʶ£¬¶øÇÒÁ˽â¹Øì¶ÄãµÄ HTTP
ËÅ·þÆ÷µÄ×î»ù±¾ÖªÊ¶£® ÄãÒ²Ó¦¸ÃÖªµÀÈçºÎд Java
³Ìʽ£¬·ñÔòÕâЩ¶¼Ã»ÓÐÒâÒ壮
1.2. Õâ·ÝÎļþ
±¾ÎĵÄ×îа汾¿ÉÒÔ´Ó´ËÕÒµ½:
http://www.orbits.com/software/Java_CGI.html.
1.3. ÈíÌåÌ×¼þ
±¾ÎÄËùÌáµ½µÄÈíÌåÌ×¼þµÄ×îа汾¿ÉÓÉÄäÃû FTP
È¡µÃftp://ftp.orbits.com/pub/software/java_cgi-0.4.tgz.
ÕâÌ×¼þ°üº¬±¾ÎÄµÄ SGML Ôʼµµ£®
ÕâЩÌ×¼þµÄÉ¢²¼±ØÐëÒÀ¾Ý GNU Library General Public License. ±¾ÎÄ¿ÉÒÀ
Linux HOWTO µÄ°æȨÉùÃ÷É¢²¼£®
Èç¹ûÄãʹÓñ¾ÈíÌ壬Ç뽫ijЩ²Î¿¼Ö¸Ïò
http://www.orbits.com/software/Java_CGI.html£¬ ÒÔ±ãÈÃÆäËüÈËÄÜÕÒµ½ Java
CGI µÄÀà±ð£®
1.4. ¹ã¸æÒ»ÏÂ
±¾ÎÄÊÇÓÉ Stellar Orbits Technology Services ËùÌṩ£®(Çëµ½
http://www.orbits.com/ ÒÔÁ˽âÎÒÃÇÊÇ×öʲ÷áµÄ£®)
_________________________________________________________________
Java CGI HOWTO ÖÐÒë°æ : ¼ò½é
Previous: Java CGI HOWTO ÖÐÒë°æ
Next: É趨ËÅ·þÆ÷ÒÔÖ´ÐÐ Java CGI ³Ìʽ (½âÊÍƪ) Java CGI HOWTO ÖÐÒë°æ :
É趨ËÅ·þÆ÷ÒÔÖ´ÐÐ Java CGI ³Ìʽ (½âÊÍƪ)
Previous: ¼ò½é
Next: É趨ËÅ·þÆ÷ÒÔÖ´ÐÐ Java CGI ³Ìʽ (¼òÂÔƪ)
_________________________________________________________________
2. É趨ËÅ·þÆ÷ÒÔÖ´ÐÐ Java CGI ³Ìʽ (½âÊÍƪ)
ÕâÒ»½Ú½ÌÄã°²×°ÎÒµÄ Java CGI
Ì×¼þ£¬ÒÔ¼°´óÁ¿µÄ½âÊÍ£¬ÈÃÄãÄܹ»Á˽âÄãµÄÐÐΪ»áµ¼ÖÂʲ÷á½á¹û£®Èç¹ûÄãÖ»Ïë°²
×°³Ìʽ¶ø²»ÏëÁ˽âΪʲ÷ᣬֱ½ÓÌøµ½ É趨ËÅ·þÆ÷ÒÔÖ´ÐÐ Java CGI ³Ìʽ
(¼òÂÔƪ)£®
2.1. ϵͳÐèÇó
±¾ÈíÌåÓ¦¸ÃÄÜÔÚÒÑ°²×° Java ³Ìʽ·¢Õ¹¹¤¾ßµÄÈκÎÀà UNIX µÄ web
ËÅ·þÆ÷ÉÏ°²×°£®ÎÒ½«Ëü×°ÔÚÖ´ÐÐ apache ËÅ·þÆ÷µÄ Debian Linux ϵͳÉÏ£®
Èç¹ûÄã·¢¾õËüÎÞ·¨ÔÚÄãµÄËÅ·þÆ÷ÉÏÔË×÷£¬ÇëÓëÎÒÁªÂç: dhs@orbits.com.
²»ÐÒµÄÊÇ£¬Java Ö´ÐÐʱÆÚ½âÒëÆ÷ËƺõÊdzԼÇÒäÌåµÄ¹ÖÎï -- Èç¹ûÄ㽫ʹÓÃÐí¶à
Java CGI ³ÌʽµÄ»°Äã¿ÉÄÜÒªÔÙ¶ªÊý MB µÄ RAM µ½ÄãµÄËÅ·þÆ÷À
2.2. Java CGI ¸¨ÖúÈíÌå
ÎÒдµÄ¸¨ÖúÈíÌå¾Í½Ð×ö Java CGI£®Äã¿É´Ó
ftp://www.orbits.com/pub/software/java_cgi-0.4.tgz
È¡µÃ(°æ±¾ºÅÂë¿ÉÄÜ»á¸Ä±ä)£®
2.3. ½â¿ªÔʼµµ
ÕÒÒ»¸öºÏÊʵÄĿ¼½«Ì×¼þ½â¿ª£®
(Èç¹ûÄ㻹ûÓбê×¼·ÅÖÃÈíÌåµÄµØ·½£¬ÎÒ½¨ÒéÄã·ÅÔÚ /usr/local/src£®)
ÓÃÕâ¸öÖ¸Áî½â¿ªÌ×¼þ:
gzip -dc java_cgi-0.4.tgz | tar -xvf -
Õâ»á²úÉúÒ»¸ö½Ð java_cgi-0.4 µÄĿ¼£®
ÔÚÄÇÀïÄã¿ÉÒÔÕÒµ½±¾ÎÄÆäËüµØ·½Ìáµ½µÄµµ°¸£®
(Èç¹û°æ±¾ºÅÂë¸Ä±äÁË£¬¾Í¸ÄÓÃÄÇÌ×¼þÀïµÄ£®)
2.4. ¾ö¶¨ÄãµÄ±¾µØĿ¼²ßÂÔ
Äã±ØÐë¾ö¶¨ÈÃÄãµÄ Java CGI ³ÌʽסÔÚÄÇÀ Ò»°ãÀ´Ëµ£¬Äã»áÏ£Íû·ÅÔÚºÍÄãµÄ
cgi-bin ƽÐеÄĿ¼£® ÎÒµÄ apache ËÅ·þÆ÷É趨ʹÓà /var/web/cgi-bin Ϊ
cgi-bin Ŀ¼£¬ Òò´ËÎÒÓà /var/web/javacgi ×÷Ϊ·ÅÖà Java CGI
³ÌʽµÄµØ·½£® Äã¿ÉÄܲ»»áÏëÈý«ÄãµÄ Java CGI ³Ìʽ·Å½øijһÒÑ´æÔÚµÄ
CLASSPATH Ŀ¼£® ±à¼ Makefile À´·´Ó¦ÄãµÄϵͳÅäÖã®È·¶¨ÄãÓà root
Ç©ÈëÈ»ááÖ´ÐÐ make install£® Õ⽫±àÒë Java ³Ìʽ£¬ÐÞ¸Ä java.cgi
Ö¸Áî¸åÒÔ·ûºÏÄãµÄϵͳ£¬²¢ÇÒ½«³Ìʽ°²×°½øÊʵ±µÄλÖã®Èç¹ûÄãÏ£ÍûÓµÓб¾ÎĵÄ
HTML °æ±¾ÒÔ¼°Ò»·Ý HTML ²âÊÔÎļþ£¬¸ÄÓà make all£®
2.5. ²âÊÔÄãµÄ°²×°
Óɱ¾Ì×¼þ°²×°µÄ HTML Îļþ½Ð×ö javacgitest.html, javaemailtest.html ÒÔ¼°
javahtmltest.html£® Èç¹ûÄãÔÚÇ°½ÚʹÓà make all£¬ËüÃÇ»á·ÅÔÚÄãì¶ Makefile
ÖÐÖ¸¶¨µÄ WEBDIR Ŀ¼ÖУ® Èç¹û²»ÊÇ£¬Äã¿ÉÒÔÖ´ÐÐ make test ´Ó
javacgitest.html-dist, javaemailtest.html-dist ÒÔ¼°
javahtmltest.html-dist À´½¨Á¢ËüÃÇ£®
µ±ÄãÈ·¶¨ÄãµÄ°²×°¿ÉÒÔÕýÈ·ÔË×÷áᣬÄã¿ÉÄÜÏ£Íû´ÓÄãµÄ JAVACGI Ŀ¼ÒƳý
CGI_Test, Email_Test ÒÔ¼° HTML_Test Àà±ð£¬»¹ÓÐ´Ó WEBDIR Ŀ¼ÒƳý
javacgitest.html, javaemailtest.html
ÒÔ¼°javahtmltest.html£¬ÒòΪËüÃÇ»áÏÔʾӦ¸ÃÖ»ÓÐËÅ·þÆ÷¹ÜÀíÕ߲ſ´µÃµ½µÄʹÓ
ÃÕß×ÊѶ£®
_________________________________________________________________
Java CGI HOWTO ÖÐÒë°æ : É趨ËÅ·þÆ÷ÒÔÖ´ÐÐ Java CGI ³Ìʽ (½âÊÍƪ)
Previous: ¼ò½é
Next: É趨ËÅ·þÆ÷ÒÔÖ´ÐÐ Java CGI ³Ìʽ (¼òÂÔƪ) Java CGI HOWTO ÖÐÒë°æ :
É趨ËÅ·þÆ÷ÒÔÖ´ÐÐ Java CGI ³Ìʽ (¼òÂÔƪ)
Previous: É趨ËÅ·þÆ÷ÒÔÖ´ÐÐ Java CGI ³Ìʽ (½âÊÍƪ)
Next: Ö´ÐÐÒ»¸ö Java CGI ³Ìʽ
_________________________________________________________________
3. É趨ËÅ·þÆ÷ÒÔÖ´ÐÐ Java CGI ³Ìʽ (¼òÂÔƪ)
1. ´Óftp://www.orbits.com/pub/software/java_cgi-0.4.tgz. È¡»Ø Java
CGI Ì×¼þ£®(°æ±¾ºÅÂë¿ÉÄÜ»á¸Ä±ä£®)
2. ÓÃÕâ¸öÖ¸Áî½â¿ªÌ×¼þ:
gzip -dc java_cgi-0.4.tgz | tar -xvf -
(Èç¹û°æ±¾ºÅÂë¸Ä±äÁË£¬¾Í¸ÄÓÃÄÇÌ×¼þÀïµÄ£®)
3. ÐÞ¸ÄÔÚвúÉúµÄ java_cgi-0.4 Ŀ¼ÀïµÄ Makefile ÒÔ·ûºÏÄãµÄϵͳ£®
4. ÒÔ root Éí·Ý£¬Ö´ÐÐ make install£® Õ⽫±àÒë Java
³Ìʽ£¬¼ÓÉÏÄãϵͳÌض¨µÄ×ÊѶ²¢°²×°Ðí¶àµµ°¸£® Èç¹ûÄãÏ£ÍûÓµÓб¾ÎĵÄ
HTML °æ±¾ÒÔ¼°Ò»·Ý HTML ²âÊÔÎļþ£¬¸ÄÓà make all£®
5. È»ááÓ¦¸Ã¾Í¿ÉÒÔÓÃÁË£®
_________________________________________________________________
Java CGI HOWTO ÖÐÒë°æ : É趨ËÅ·þÆ÷ÒÔÖ´ÐÐ Java CGI ³Ìʽ (¼òÂÔƪ)
Previous: É趨ËÅ·þÆ÷ÒÔÖ´ÐÐ Java CGI ³Ìʽ (½âÊÍƪ)
Next: Ö´ÐÐÒ»¸ö Java CGI ³Ìʽ Java CGI HOWTO ÖÐÒë°æ : Ö´ÐÐÒ»¸ö Java CGI
³Ìʽ
Previous: É趨ËÅ·þÆ÷ÒÔÖ´ÐÐ Java CGI ³Ìʽ (¼òÂÔƪ)
Next: ʹÓà Java CGI Àà±ð
_________________________________________________________________
4. Ö´ÐÐÒ»¸ö Java CGI ³Ìʽ
4.1. ÒÔ CGI ģʽִÐÐ Java ³ÌʽµÄÕÏ°-
´Ó web ËÅ·þÆ÷Ö´ÐÐ Java ³ÌʽÓÐÁ½¸öÖ÷ÒªµÄÎÊÌâ:
4.1.1. Äã²»ÄÜÏñÒ»°ãÖ´ÐеµÒ»ÑùÖ´ÐÐ Java ³Ìʽ
Äã±ØÐèÖ´ÐÐ Java
µÄÖ´ÐÐʱ¿Ì(run-time)½âÒëÆ÷²¢ÇÒÒÔÃüÁîÁеķ½Ê½Ìṩ³õʼÀà±ð(³ÌʽִÐÐËùÐè)
£® ÔÚÒ»¸ö HTML form ÀïÃæûÓа취ÌṩÃüÁîÁиø web ËÅ·þÆ÷£®
4.1.2. Java ³ÌʽûÓÐÒ»°ãµÄ·½·¨¿ÉÒÔÈ¡µÃ»·¾³±äÊý
Java ³ÌʽËùÐèµÄÿ¸ö»·¾³±äÊý¶¼±ØÐè±»´«È룮 (ÔÚ Java ³ÌʽÖÐ)ûÓÐÀàËÆ C
ÓïÑ﵀ getenv() º¯Êý£®
4.2. Ö´ÐÐ Java CGI ½â¾öÎÊÌâ
ΪÁË´¦ÀíÕâЩÀ§ÄÑ£¬ÎÒдÁËÒ»¸ö CGI Ö¸Áî¸å³Ìʽ£¬Ìṩ Java
½âÒëÆ÷ËùÐèµÄ×ÊѶ£®
4.2.1. java.cgi Ö¸Áî¸å
Õâ¸öÖ¸Áî¸å¹ÜÀí HTTP ËÅ·þÆ÷ÓëÄãÏ£ÍûʹÓÃµÄ Java CGI ³Ìʽ֮¼äµÄ»¥¶¯£®
Ëü´Ó server ¶ËÌṩµÄ×ÊÁÏÖÐÈ¡³öÄãÏëÒªÖ´ÐгÌʽµÄÃû³Æ£®
Ëü½«ËùÓеĻ·¾³±äÊý×ÊÁϽ«÷Ûµ½Ò»¸öÔÝ´æµµÀȻáᣬËü½«Õâ¸öµµ°¸ÒÔ¼°³ÌʽÃû
³Æ¼ÓÃüÁîÁÐÖУ¬ Ö´ÐÐ Java µÄÖ´ÐÐʱ¿Ì½âÒëÆ÷£®
java.cgi Ö¸Áî¸åµÄÉ趨Óë°²×°ÔÚ ¾ö¶¨ÄãµÄ±¾µØĿ¼²ßÂÔ Ò»½Ú˵Ã÷£®
4.2.2. ´Ó HTML form ÖÐÒý·¢ java.cgi
ʹÓà Java CGI ³ÌʽµÄ HTML form ÒÔÏÂÃæµÄ·½Ê½Ö¸¶¨ÆäÐÐΪ:
<form action="/cgi-bin/java.cgi/CGI_Test" method="POST">
ÆäÖÐ /cgi-bin/ ÊÇÄã±¾µØ¶ËµÄ CGI ¶þ½øλִÐеµÄ¿Â¼£¬ java.cgi
ÊÇÔÊÐíÎÒÃÇ´Ó web ÉÏÖ´ÐÐ Java ³ÌʽµÄÇ°¶Ë£¬ ¶ø CGI_Test ÊÇÒ»¸öÓûÖ´ÐеÄ
Java ³ÌʽÃû³ÆµÄÀý×Ó£®
_________________________________________________________________
Java CGI HOWTO ÖÐÒë°æ : Ö´ÐÐÒ»¸ö Java CGI ³Ìʽ
Previous: É趨ËÅ·þÆ÷ÒÔÖ´ÐÐ Java CGI ³Ìʽ (¼òÂÔƪ)
Next: ʹÓà Java CGI Àà±ð Java CGI HOWTO ÖÐÒë°æ : ʹÓà Java CGI Àà±ð
Previous: Ö´ÐÐÒ»¸ö Java CGI ³Ìʽ
Next: δÀ´µÄ¼Æ»
_________________________________________________________________
5. ʹÓà Java CGI Àà±ð
ĿǰΪֹ֧ԮÈý¸öÖ÷ÒªÀà±ð -- CGI, Email ÒÔ¼° HTML£®
ÎÒÕýÔÚ¿¼ÂÇ·Ö±ð¼ÓÉÏ´¦Àí MIME ¸ñʽÊäÈëÓëÊä³öµÄÀà±ð -- MIMEin & MIMEout£®
Ò²ÓÐһЩÓÃÀ´Ö§Ô®ºÍ²âÊÔµÄÀà±ð£® CGI_Test, Email_Test ÒÔ¼° HTML_Test
ÊÇÄÃÀ´²âÊÔÄãµÄ°²×°Óõģ®
ÄãÒ²¿ÉÄÃÀ´µ±×öÄã×Ô¼º³ÌʽÖÐʹÓÃÕâЩÀà±ð¿âµÄÆðµã£® Text Àà±ðÊÇ Email Óë
HTML µÄ»ùµ×Àà±ð£®
5.1. CGI
5.1.1. Àà±ðÓï·¨
public class CGI
5.1.2. Àà±ðÃèÊö
CGI Àà±ð³ÖÓеġ¸CGI ×ÊѶ¡¹ -- web ËÅ·þÆ÷ËùÉ趨µÄ»·¾³±äÊýÒÔ¼°°´ÏÂ
submit ʱÓÉ form Ëù´«ËÍÀ´µÄÃû³Æ/ÊýÖµ£® ËùÓеÄ×ÊѶ¶¼±»´æ·ÅÔÚÀà±ðÎï¼þ
Properties ÖУ®
Õâ¸öÀà±ðÎ»ì¶ ``Orbits.net'' °ü×°(package)ÖУ®
5.1.3. ³ÉÔ±ÕªÒª
_________________________________________________________________
CGI() // ½¨¹¹×Ó
getNames() // È¡µÃÃû³ÆµÄ´®ÁÐ
getValue() // È¡µÃÖ¸¶¨Ãû³ÆµÄÖµ
_________________________________________________________________
5.1.4. Çë²ÎÔÄ
CGI_Test.
5.1.5. CGI()
Ä¿µÄ
½¨¹¹Ò»°üº¬¿ÉÓà CGI ×ÊÁϵÄÎï¼þ
Óï·¨
public CGI()
ÃèÊö
µ±Ò» CGI Îï¼þ±»½¨Á¢Ê±£¬ËùÓпÉÓÃµÄ CGI
×ÊÁϱ»´æ·ÅÔÚÐÂÎï¼þµÄ¾Ö²¿´¢´æ¿Õ¼äÖУ®
5.1.6. getNames()
Ä¿µÄ
ÁгöÒѶ¨Òå¶ÔÓ¦ÖµµÄÃû³Æ£®
Óï·¨
public Enumeration getNames ()
ÃèÊö
ÌṩËùÓÐÒѶ¨Òå¶ÔÓ¦ÖµµÄÃû³ÆµÄÍêÕûÁÐ±í£®
·µ»Ø
ËùÓÐÃû³ÆµÄ Enumeration Îï¼þ£®
5.1.7. getValue()
Ä¿µÄ
È¡»ØËùÖ¸¶¨¶ÔÓ¦ì¶ name µÄ value£®
Óï·¨
public String getValue ( String name )
ÃèÊö
Õâ¸ö·½·¨ÌṩÓÉ HTML form ËÍÈëµÄ names Óë values Ö®¼äµÄ¶ÔÓ¦£®
²ÎÊý
name
ËùÑ¡ÔñµÄ¼üÖµ£®
·µ»Ø
Ò»¸ö°üº¬¶ÔÓ¦ÖµµÄ String Îï¼þ£®
5.2. CGI_Test
Õâ¸öÀà±ðÌṩÁ½¸ö¹¦ÄÜ£¬Ò»¸öÈçºÎʹÓà CGI Àà±ðµÄÀý×ÓÒÔ¼°Ò»¸öÓÃÀ´È·¶¨ Java
CGI Ì×¼þÔË×÷Õý³£µÄ²âÊÔ³Ìʽ£®
5.2.1. ³ÉÔ±ÕªÒª
_________________________________________________________________
main() // Program main().
_________________________________________________________________
5.2.2. Çë²ÎÔÄ
CGI.
5.2.3. main()
Ä¿µÄ
Ìṩ main() ·½·¨£®
Óï·¨
public static void main( String argv[] )
ÃèÊö
ÕâÊÇ CGI
³ÌʽµÄÈë¿Ú£¬Ö»²»¹ý·µ»Ø¿ÉÓõÄÃû³Æ/ÊýÖµ¶ÔÓëÆäÏÖÖµµÄÁÐ±í£®
²ÎÊý
argv[]
ÓÉ java.cgi Ö¸Áî¸å´«ÈëµÄ²ÎÊý£®Ä¿Ç°Î´Ê¹Óã®
5.3. Email
5.3.1. Àà±ðÓï·¨
public class Email extends Text
5.3.2. Àà±ðÃèÊö
ѶϢÓÉ Text Àà±ðµÄ add*() ·½·¨Ëù½¨Á¢£¬¼ÓÈëµç×ÓÓʼþרÓõķ½·¨£®
Íê³ÉáᣬѶϢ±»Ë͵½ËüµÄÄ¿µÄµØ£®
Õâ¸öÀà±ðÎ»ì¶ ``Orbits.net'' °ü×°ÖУ®
5.3.3. ³ÉÔ±ÕªÒª
_________________________________________________________________
Email() // ½¨¹¹×Ó
send() // Ëͳöµç×ÓÓʼþѶϢ
sendTo() // Ôö¼ÓѶϢµÄÄ¿µÄµØ
subject() // É趨ѶϢµÄÖ÷Ìâ
_________________________________________________________________
5.3.4. Çë²ÎÔÄ
Email_Test, Text.
5.3.5. Email()
Ä¿µÄ
½¨Á¢Ò»°üº¬µç×ÓÓʼþѶϢµÄÎï¼þ£®
Óï·¨
public Email()
ÃèÊö
½¨Á¢Ò»¿ÕµÄѶϢÒÔÀûÓÉ´ËÀà±ð·½·¨¼ÓÒÔÍê³É£®
Çë²ÎÔÄ
Text.
5.3.6. send()
Ä¿µÄ
Ëͳöµç×ÓÓʼþѶϢ£®
Óï·¨
public void send ()
ÃèÊö
±¾·½·¨±àÅŲ¢ËͳöѶϢ£®Èç¹ûÄ¿µÄλַ»¹Î´É趨£¬½«²»»áÓж¯×÷·¢Éú£®
5.3.7. sendTo()
Ä¿µÄ
Ôö¼Ó±¾Ñ¶Ï¢µÄÄ¿µÄµØ£®
Óï·¨
public String sendTo ( String address )
ÃèÊö
½« address
¼ÓÈ뵽ĿµÄµØÁбíÖУ®Ò»·Ýµç×ÓÓʼþÄ¿µÄµØµÄÊýÄ¿ÊÇûÓÐÏÞÖƵģ®
²»¹ýÎÒÏàÐÅÈç¹ûÄ㽨Á˹ý´óµÄÁÐ±í£¬Ä㽫¿ÉÄܻᳬ¹ýÄãµÄÓʼþ´«ËÍ´úÀí³
Ìʽ(MTA) ËùÄܽÓÊܵĴóС»òÓùâÄãµÄ¼ÇÒäÌ壮
²ÎÊý
address
±¾Ñ¶Ï¢ÓûËÍ´ïµÄÒ»¸öÄ¿µÄµØ£®
5.3.8. subject()
Ä¿µÄ
É趨±¾Ñ¶Ï¢µÄÖ÷Ì⣮
Óï·¨
public void subject ( String subject )
ÃèÊö
±¾·½·¨É趨µç×ÓÓʼþµÄ Subject:
À¸Î»£®Èç¹ûºô½Ð³¬¹ýÒ»´ÎÒÔÉÏ£¬»áʹÓÃ×îááÒ»´Îºô½ÐµÄ½á¹û£®
²ÎÊý
subject
Subject: À¸Î»µÄÎÄ×Ö£®
5.4. Email_Test
Õâ¸öÀà±ðÌṩһ¸öÈçºÎʹÓà Email Àà±ðµÄÀý×ÓÒÔ¼°Ò»¸öÓÃÀ´È·¶¨ Java CGI
Ì×¼þÔË×÷Õý³£µÄ²âÊÔ³Ìʽ£®
5.4.1. ³ÉÔ±ÕªÒª
_________________________________________________________________
main() // Program main().
_________________________________________________________________
5.4.2. Çë²ÎÔÄ
Email.
5.4.3. main()
Ä¿µÄ
Ìṩ main() ·½·¨£®
Óï·¨
public static void main( String argv[] )
ÃèÊö
ÕâÊÇ CGI ³ÌʽµÄÈë¿Ú£¬·µ»Ø¿ÉÓõÄÃû³Æ/ÊýÖµ¶ÔÓëÆäÏÖÖµµÄÁÐ±í£®
ËüÒ²½«ÁбíË͵½ÓÉ Email ±äÊýËùÖ¸¶¨µÄλַ£®
²ÎÊý
argv[]
ÓÉ java.cgi Ö¸Áî¸å´«ÈëµÄ²ÎÊý£®Ä¿Ç°Î´Ê¹Óã®
5.5. HTML
5.5.1. Àà±ðÓï·¨
public class HTML extends Text
5.5.2. Àà±ðÃèÊö
ѶϢÓÉ Text Àà±ðµÄ add*() ·½·¨Ëù½¨Á¢£¬²¢¼ÓÈë HTML רÓõķ½·¨£®
Íê³ÉáᣬѶϢ±»Ë͵½ËüµÄÄ¿µÄµØ£®
Ä¿Ç°£¬»¹Ã»ÓдíÎó¼ì²é»úÖÆÒÔÈ·±£ÁÐ±í½¨Á¢µÄ·½·¨±»ÒÔÕýÈ·µÄ˳ÐòʹÓã®
Òò´Ë³ÌʽÉè¼ÆÕß±ØÐë×ÔÐÐÈ·¶¨Ã»ÓÐÎ¥·´ HTML µÄÓï·¨£®
Õâ¸öÀà±ðÎ»ì¶ ``Orbits.net'' °ü×°ÖУ®
5.5.3. ³ÉÔ±ÕªÒª
_________________________________________________________________
HTML() // ½¨¹¹×Ó
author() // É趨Îļþ×÷ÕßµÄÃû×Ö
definitionList() // Æðʼһ¶¨ÒåÁбí
definitionListTerm() // ÔÚ¶¨ÒåÁбíÖÐÔö¼ÓÒ»ÏîÄ¿
endList() // ½áÊøÁбí
listItem() // ÔÚÁбíÖÐÔö¼ÓÒ»ÏîÄ¿
send() // Ëͳö´Ë HTML ѶϢ
title() // É趨Îļþ±êÌâµÄÎÄ×Ö
_________________________________________________________________
5.5.4. Çë²ÎÔÄ
HTML_Test, Text.
5.5.5. HTML()
Ä¿µÄ
½¨Á¢Ò»°üº¬ HTML ѶϢµÄÎï¼þ£®
Óï·¨
public HTML()
ÃèÊö
½¨Á¢Ò»¿ÕµÄѶϢÒÔÀûÓÉ HTML ·½·¨¼ÓÒÔÍê³É£®
Çë²ÎÔÄ
Text.
5.5.6. author()
Ä¿µÄ
É趨Îļþ×÷ÕßµÄÃû×Ö£®
Óï·¨
public void author ( String author )
ÃèÊö
½«ÎļþµÄ×÷ÕßÃû×ÖÉ趨Ϊ author£®
²ÎÊý
author
ÓÃÀ´×÷Ϊ´ËѶϢ×÷ÕßµÄÎÄ×Ö£®
Çë²ÎÔÄ
title().
5.5.7. definitionList()
Ä¿µÄ
Æðʼһ¶¨ÒåÁÐ±í£®
Óï·¨
public void definitionList ()
ÃèÊö
Æðʼһ¶¨ÒåÁÐ±í£®
Ò»¸ö¶¨ÒåÁбíÊÇÒ»ÖÖÌرðµÄÁÐ±í£¬ÁбíÖеÄÿһÏîÊÇÓÉ ÏîÄ¿
Æäáá¸úÖø¶¨ÒåµÄ ÎÄ×Ö
ËùÐγɵģ®Ò»¶¨ÒåÁбíµÄÆðʼӦ¸úÖø(ÖÁÉÙ)Ò»ÏîÄ¿/ÎÄ×ÖÅä¶ÔÒÔ¼°Ò»¸ö
endList() ·½·¨µÄºô½Ð£® Çë×¢Ò⣬ĿǰÁÐ±í²»ÄÜÊdz²×´µÄ£®
Çë²ÎÔÄ
definitionListTerm(), endList(), listItem().
5.5.8. definitionListTerm()
Ä¿µÄ
ÔÚ¶¨ÒåÁбíÖÐÔö¼ÓÒ»ÏîÄ¿£®
Óï·¨
public void definitionListTerm ()
ÃèÊö
ÔÚ¶¨ÒåÁбíÖÐÔö¼ÓÒ»ÏîÄ¿£®
Ä¿Ç°ÁбíµÄÏîÄ¿²¿·ÝµÄÎÄ×ÖÓ¦¸ÃÔÚ´Ë·½·¨±»ºô½Ðáá²¢ÇÒÔÚ¶ÔÓ¦µÄ
listItem ·½·¨±»ºô½ÐÇ°¼ÓÈ룮
Çë²ÎÔÄ
definitionList(), listItem().
5.5.9. endList()
Ä¿µÄ
½áÊøÒ»ÁÐ±í£®
Óï·¨
public void endList ()
ÃèÊö
±¾·½·¨½áÊøÒ»ÁÐ±í£®×¢Ò⣬ĿǰÁÐ±í²»ÄÜÊdz²×´µÄ£®
Çë²ÎÔÄ
definitionList().
5.5.10. listItem()
Ä¿µÄ
ÔÚÁбíÖÐÔö¼ÓÒ»ÏîÄ¿£®
Óï·¨
public void listItem ()
public void listItem ( String item )
public boolean listItem ( String term, String item )
ÃèÊö
ÔÚÁбíÖÐÔö¼ÓÒ»ÏîÄ¿£®
Èç¹ûʹÓõÚÒ»ÖÖÐÎʽ£¬Ä¿Ç°ÁбíÏîÄ¿µÄÎÄ×ÖÓ¦ÔÚ´Ë·½·¨±»½Ðáá²¢ÔÚÈκÎÆ
äËüÁÐ±í·½·¨±»ºô½ÐÇ°¼ÓÈ룮 ÔÚµÚ¶þ¼°µÚÈýÖÖÐÎʽÖУ¬item
ÎÄ×Ö±»Ö¸¶¨Îª·½·¨µÄ²ÎÊý¶ø²»ÊÇÔÚÆäáá±»¼ÓÈ룮µÚÈýÖÖÐÎʽÊǶ¨ÒåÁбí×
¨Óò¢ÇÒͬʱָ¶¨ÁбíµÄÏîÄ¿Ó붨ÒåÎÄ×Ö²¿·Ý£®
²ÎÊý
item
´ËÁбíÏîÄ¿µÄÎÄ×Ö£®
term
´Ë¶¨ÒåÁбíµÄÏîÄ¿²¿·ÝµÄÎÄ×Ö£®
Çë²ÎÔÄ
definitionList(), definitionListTerm(), endList().
5.5.11. send()
Ä¿µÄ
Ëͳö´Ë HTML ѶϢ£®
Óï·¨
public void send ()
ÃèÊö
Ëͳö´Ë HTML ѶϢ£®
5.5.12. title()
Ä¿µÄ
É趨Îļþ±êÌâµÄÎÄ×Ö£®
Óï·¨
public void title ( String title )
ÃèÊö
É趨´ËÎļþµÄ±êÌâÎÄ×Ö£®
²ÎÊý
title
´ËÎļþ±êÌâµÄÎÄ×Ö£®
Çë²ÎÔÄ
author().
5.6. HTML_Test
Õâ¸öÀà±ðÌṩһ¸öÈçºÎʹÓà HTML Àà±ðµÄÀý×ÓÒÔ¼°Ò»¸öÓÃÀ´È·¶¨ Java CGI
Ì×¼þÔË×÷Õý³£µÄ²âÊÔ³Ìʽ£®
5.6.1. ³ÉÔ±ÕªÒª
_________________________________________________________________
main() // Program main().
_________________________________________________________________
5.6.2. Çë²ÎÔÄ
HTML.
5.6.3. main()
Ä¿µÄ
Ìṩ main() ·½·¨£®
Óï·¨
public static void main( String argv[] )
ÃèÊö
ÕâÊÇ CGI ³ÌʽµÄÈë¿Ú£¬·µ»ØÔÚÒ» HTML
ÎļþÖпÉÓõÄÃû³Æ/ÊýÖµÅä¶ÔÓëÆäÏÖÖµµÄÁÐ±í£¬²¢½«Ã¿Ò»Ãû³Æ/ÊýÖµÅä¶ÔÏ
ÔʾÔÚÒ»¶¨ÒåÁбíµÄÔªËØÀ
²ÎÊý
argv[]
ÓÉ java.cgi Ö¸Áî¸å´«ÈëµÄ²ÎÊý£®Ä¿Ç°Î´Ê¹Óã®
5.7. Text
5.7.1. Àà±ðÓï·¨
public abstract class Text
5.7.2. Àà±ðÃèÊö
±¾Àà±ðΪ Email Óë HTML µÄ»ù´¡Àà±ð£®
ѶϢÒÔ´ËÀà±ðµÄ·½·¨½¨Á¢£¬²¢ÒÔÑÜÉúÀà±ðµÄ·½·¨Íê³É²¢±àÅÅ£®
Õâ¸öÀà±ðÎ»ì¶ ``Orbits.net'' °ü×°ÖУ®
5.7.3. ³ÉÔ±ÕªÒª
_________________________________________________________________
Text() // ½¨¹¹×Ó
add() // ¼ÓÈëÎÄ×Öµ½´ËÎï¼þ
addLineBreak() // ¼ÓÈë·ÖÐзûºÅ
addParagraph() // ¼ÓÈë·Ö¶Î·ûºÅ
_________________________________________________________________
5.7.4. Çë²ÎÔÄ
Email, HTML.
5.7.5. add()
Ä¿µÄ
ÔÚ´ËÏîÄ¿ÖмÓÈëÎÄ×Ö£®
Óï·¨
public void add ( char addition )
public void add ( String addition )
public void add ( StringBuffer addition )
ÃèÊö
ÔÚÕâ¸öÎÄ×ÖÏîÄ¿µÄÄÚÈÝÖмÓÈë addition£®
²ÎÊý
addition
¼ÓÈë´ËÎÄ×ÖÏîÄ¿µÄÎÄ×Ö£®
Çë²ÎÔÄ
addLineBreak(), addParagraph().
5.7.6. addLineBreak()
Ä¿µÄ
Ç¿ÆÈÔÚÄ¿Ç°ÎÄ×ÖλÖ÷ÖÐУ®
Óï·¨
public void addLineBreak ()
ÃèÊö
ÔÚĿǰλÖüÓÈëÒ»·ÖÐзûºÅ£®
Çë²ÎÔÄ
add(), addParagraph().
5.7.7. addParagraph()
Ä¿µÄ
ÆðʼһеĶÎÂ䣮
Óï·¨
public void add ()
ÃèÊö
ÔÚÄ¿Ç°µÄÎÄ×ÖλÖÃÆðʼһеĶÎÂ䣮
Çë²ÎÔÄ
add(), addLineBreak().
_________________________________________________________________
Java CGI HOWTO ÖÐÒë°æ : ʹÓà Java CGI Àà±ð
Previous: Ö´ÐÐÒ»¸ö Java CGI ³Ìʽ
Next: δÀ´µÄ¼Æ» Java CGI HOWTO ÖÐÒë°æ : δÀ´µÄ¼Æ»
Previous: ʹÓà Java CGI Àà±ð
Next: °æ±¾Ð޸ļǼ
_________________________________________________________________
6. δÀ´µÄ¼Æ»-
* Email Àà±ðµÄÀ©³ä:
Email( int capacity )
ÓÃÀ´µ±ÎÒÃÇÖªµÀÐè¶àÉÙ¿Õ¼äÀ´´¢´æѶϢʱ£®
sendTo( String [] address )
Ôö¼ÓÔʼµç×ÓÓʼþÄ¿µÄµØµÄÁÐ±í£®
sendCc( String address )
Ôö¼ÓÒ»¸ö¸´ÖƵç×ÓÓʼþÄ¿µÄµØ£®
sendCc( String [] address )
Ôö¼Ó¸´ÖƵç×ÓÓʼþÄ¿µÄµØµÄÁÐ±í£®
sendBcc( String address )
Ôö¼ÓÒ»¸ö Blind Carbon-Copy µÄµç×ÓÓʼþÄ¿µÄµØ£®
sendBcc( String [] address )
Ôö¼Ó Blind Carbon-Copy µÄµç×ÓÓʼþÄ¿µÄµØÁбí
* HTML Àà±ðµÄÀ©³ä:
HTML( int capacity )
ÓÃÀ´µ±ÎÒÃÇÖªµÀÐè¶àÉÙ¿Õ¼äÀ´´¢´æѶϢʱ£®
public void unorderedList()
ÆðʼһÎÞÐòÁÐ±í£®
public void orderedList()
ÆðʼһÓÐÐòÁÐ±í£®
public void directoryList()
ÆðʼһĿ¼ÁÐ±í£®
public void menuList()
Æðʼһѡµ¥ÁÐ±í£®
void anchor( String anchorName )
Ö¸¶¨Ò»Ãª(anchor)£®
void link( String url, String text )
Ö¸¶¨Ò»Á¬½á£®
void applet( String url, String altText )
Ö¸¶¨Ò» applet Á¬½á£®
* ÔÊÐí³²×´µÄ HTML ÁÐ±í£®
* Ôö¼Ó´íÎó¼ì²éÂëÒÔÇ¿ÆÈÐÞÕý HTML Áбí¸ñʽÂëµÄ˳Ðò£®
* »·¾³±äÊý×ÊÁϵĵµ°¸Î»ÖÃÓ¦ÄÜÓÉ Makefile É趨£®
* ³ýÈ¥ÔÚ´¦Àí GET ·½·¨µÄ×ÊÁÏ´«ËÍʱ³öÏÖÖ®¼ÙµÄ¿ÕÃû³Æ/ÊýÖµ¶Ô£®
* ¿¼ÂÇÈà CGI ʵ×÷ java.util.Enumeration ½çÃæÒÔÒÀÐòµØÌṩ±äÊýÃû³Æ£®
* ¼ÓÈëÒ» Test Àà±ð£¬Ê¹Óñ¾Ì×¼þÖеÄÿ¸ö·½·¨£®
* ˵Ã÷ CGI_Test, Email_Test Óë HTML_Test
ÈçºÎÏ໥½¨Á¢ÒÔÌṩÕì´íÄ¿µÄÓõĽ¥½ø²âÊÔ£®
* ˵Ã÷ÈçºÎ²âÊÔʹÓñ¾Ì×¼þµÄÿһ¸öÌØá磮
_________________________________________________________________
Java CGI HOWTO ÖÐÒë°æ : δÀ´µÄ¼Æ»
Previous: ʹÓà Java CGI Àà±ð
Next: °æ±¾Ð޸ļǼ Java CGI HOWTO ÖÐÒë°æ : °æ±¾Ð޸ļǼ
Previous: δÀ´µÄ¼Æ»
Next: Java CGI HOWTO ÖÐÒë°æ
_________________________________________________________________
7. °æ±¾Ð޸ļǼ
7.1. ÓÉ 0.3 µ½ 0.4 µÄÐÞ¸Ä
* ÔöÌí HTML Àà±ðÌṩµÄ»ù±¾¹¦ÄÜ£®
* Ôö¼Ó HTML_Test Àà±ðÓë javahtmltest.html-dist£®
* Ôö¼Ó HTML ·½·¨À´´¦Àí¶¨ÒåÁÐ±í£®
7.2. ÓÉ 0.2 µ½ 0.3 µÄÐÞ¸Ä
* ¼ÓÈë Text Óë Email Àà±ð£® HTML Ò²±»¼ÓÈ룬µ«´ËʱֻÊÇһС²¿·Ý¶øÒÑ£®
* ½«²»Í¬µÄÀà±ð·ÅÈë°ü×°ÖУ® Ö÷ÒªµÄÀà±ðÔÚ Orbits.net.*£¬Ö§Ô®ÓõÄÀà±ð
Text ·ÅÔÚ Orbits.text.Text£®
* ½« CGItest ¸ÄΪ CGI_Test£®
* Ôö¼Ó Email_Test Àà±ð£®
7.3. ÓÉ 0.1 µ½ 0.2 µÄÐÞ¸Ä
* »·¾³±äÊý±»·ÅÈëÒ»ÔÝ´æµµÖжø²»ÊÇÃãÇ¿¼·Èë Java ½âÒëÆ÷µÄÃüÁîÁÐÀ CGI
Àà±ðÓë java.cgi Òѱ»Ð޸ģ®
* ½« javacgitest.html Îļþ¼ÓÈë³ÉΪÌ×¼þµÄÒ»²¿·Ý£®
* °²×°Ê±ÓÉ make ËùÐ޸ĵĵµ°¸È«¶¼ÒÔ½áβ -dist À´ÃüÃû£®
_________________________________________________________________
Java CGI HOWTO ÖÐÒë°æ : °æ±¾Ð޸ļǼ
Previous: δÀ´µÄ¼Æ»
Next: Java CGI HOWTO ÖÐÒë°æ
--
m2m¡ù À´Ô´:¡¤BBS ˮľÇ廪վ bbs.net.tsinghua.edu.cn¡¤[FROM: 159.226.41.99]m
--
Enjoy Linux!
-----It's FREE!-----
¡ù À´Ô´:£®×Ï ¶¡ Ïã bbs.hit.edu.cn£®[FROM: mtlab.hit.edu.cn]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
Ò³ÃæÖ´ÐÐʱ¼ä£º412.512ºÁÃë