CGIを使って、「Hello World!」を表示します。 WebLogicServerでは、CGIサーブレットがCGIを実行しているため、利用は推奨されていません。 HelloCGIでは、WebLogicServer6.1を使った例を紹介しています。
CGIを実行すると、以下のような画面が表示されます。
| △ | HelloCGI | □ | × |
|
Hello World! CGIのサンプル(hello.cgi) | |||
ソースファイルは、以下のディレクトリに格納します。
c:\home\jp\ash\hello\hellocgi |
サンプルプログラムの主なファイル構成です。
hello.cgi HelloWorldを表示するCGIのPerlスクリプト |
以下のPerlスクリプトを作成します。
| hello.cgi |
|---|
#!c:\perl\bin\perl.exe print "Content-type: text/html; charset=Shift_JIS\r\n\r\n"; print "<html><body>\r\n"; print "<h1>Hello World!</h1>\r\n"; print "<p>CGIのサンプル(hello.cgi)</p>\r\n"; print "</body></html>\r\n"; |
以下のディレクトリにCGIを格納します。
c:\bea\wlserver6.1\config\mydomain\applications\cgi-bin |
以下のファイルを開き、<web-app>タグの子として、カレントのweb.xmlファイルの内容を追加します。
c:\bea\wlserver6.1\config\mydomain\applications\DefaultWebApp\WEB-INF\web.xml |
| web.xmlの変更内容 |
|---|
<servlet>
<servlet-name>CGIServlet</servlet-name>
<servlet-class>weblogic.servlet.CGIServlet</servlet-class>
<init-param>
<param-name>cgiDir</param-name>
<param-value>
c:\bea\wlserver6.1\config\examples\applications\cgi-bin
</param-value>
</init-param>
<init-param>
<param-name>*.cgi</param-name>
<param-value>c:\perl\bin\perl.exe</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>CGIServlet</servlet-name>
<url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>
|
以下のURLで実行できます。 実行する場合は、WebLogicサーバを起動しておく必要があります。
http://localhost:7001/cgi-bin/hello.cgi |
CGIに記述したPerlスクリプトの処理により、「Hello World!」の文字が表示されます。