JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Application Server » Tomcat  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Tomcat 如何跑 CGI ? [精華]
proshine_roger





發文: 6
積分: 0
於 2005-01-11 17:53 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我照 O'reilly Tomcat 書上所說,
將 servlets-cgi.renametojar 改為 servlets-cgi.jar
並於 Web.xml 的
<servlet><servlet-name>cgi</servlet-name>....</servlet>

<servlet-mapping>....</servlet-mapping>
註解拿掉

再把 cgi 程式放到 webapps\ROOT\WEB-INF\cgi 下

restart tomcat 後,仍無法執行
出現下面錯誤訊息
--------------------------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
java.io.IOException: CreateProcess: perl "C:\Tomcat 4.1\webapps\ROOT\WEB-INF\cgi\printenv.pl" error=2
  at java.lang.Win32Process.create(Native Method)
  at java.lang.Win32Process.<init>(Win32Process.java:66)
  at java.lang.Runtime.execInternal(Native Method)
  at java.lang.Runtime.exec(Runtime.java:566)
  at java.lang.Runtime.exec(Runtime.java:428)
  at org.apache.catalina.servlets.CGIServlet$CGIRunner.run(CGIServlet.java:1718)
  at org.apache.catalina.servlets.CGIServlet.doGet(CGIServlet.java:599)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:696)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)

--------------------------------------------------------------------------------
;我試了三台電腦,都是這個結果

請問有人可以幫幫我嗎,感謝

我的環境是 windows 2000 Professional + j2sdk1.4.2_05 + tomcat-4.1.31

printenv.pl的程式內容
--------------------------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/local/bin/perl
##
##  printenv -- demo CGI program which just prints its environment
##
 
print "Content-type: text/html\n\n";
foreach $var (sort(keys(%ENV))) {
    $val = $ENV{$var};
    $val =~ s|\n|\\n|g;
    $val =~ s|"|\\"|g;
    print "${var}=\"${val}\"\n";
}
 
`pause`


proshine_roger edited on 2005-01-12 10:13
reply to postreply to post
心是人類的最大戰場
作者 Re:Tomcat 如何跑 CGI ? [Re:proshine_roger]
jimmy14

Give me J-Power !



發文: 787
積分: 3
於 2005-01-12 00:13 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我的環境:
Windows XP Pro
JDK 1.5 + Tomcat 5.5.4 + ActivePerl 5.8
測試 OK
error=2 好像是 CreateProcess 找不到 perl
查一下 path 路徑或者在 web.xml 中加入
1
2
3
4
<init-param>
<param-name>executable</param-name>
<param-value>cmd /c</param-value>
</init-param>


reply to postreply to post
作者 Re:Tomcat 如何跑 CGI ? [Re:proshine_roger]
proshine_roger





發文: 6
積分: 0
於 2005-01-12 10:11 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Sad
加入了executable後,IE一直停在地球轉動的狀態,無法停止
還是不行耶∼可還有其他辦法嗎?

下面是我的環境變數:
1
2
3
CLASSPATH = C:\Tomcat 4.1\common\lib\servlet.jar;C:\Tomcat 4.1\common\lib
JAVA_HOME = C:\j2sdk1.4.2_05
Path += C:\j2sdk1.4.2_05;C:\j2sdk1.4.2_05\bin


reply to postreply to post
心是人類的最大戰場
作者 Re:Tomcat 如何跑 CGI ? [Re:proshine_roger]
jimmy14

Give me J-Power !



發文: 787
積分: 3
於 2005-01-12 12:17 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
c:\perl\bin 是否有放在 PATH 環境變數裡 ?
我比較好奇的是為什麼會採用 Tomcat + Perl CGI ?
有沒有試過 (Apache + Perl CGI) + Tomcat ?


reply to postreply to post
作者 Re:Tomcat 如何跑 CGI ? [Re:jimmy14]
proshine_roger





發文: 6
積分: 0
於 2005-01-12 12:38 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
因為環境有被限制,所以只能採用 Tomcat + Perl CGI

網管的環境是 2003 + IIS + JDK + Tomcat ,可以正常執行∼

但我的 2000 + JDK + Tomcat,怎麼試就是 error = 2

去爬文,上面大部份也都是指 PATH 問題(但我的PATH沒指錯啊)

搞得我現在把servlets-cgi.jar反組譯,一個一個去查∼

@@快吐血了∼


reply to postreply to post
心是人類的最大戰場
作者 Re:Tomcat 如何跑 CGI ? [Re:proshine_roger]
jimmy14

Give me J-Power !



發文: 787
積分: 3
於 2005-01-12 14:12 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我試了 Win2K Pro + JDK 1.4.2_06 + Tomcat 4.1.31
跑起來也是 OK,
你有試過在 command 下執行嗎 ?
perl "C:\Tomcat 4.1\webapps\ROOT\WEB-INF\cgi\printenv.pl"

底下是我的執行結果
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
C:\Documents and Settings\LeeJimmy>perl "C:\Apache\Tomcat 4.1\webapps\ROOT\WEB-I
NF\cgi\printenv.pl"
Content-type: text/html
 
ALLUSERSPROFILE="C:\Documents and Settings\All Users"
ANT_HOME="C:\apache-ant-1.6.2"
APPDATA="C:\Documents and Settings\LeeJimmy\Application Data"
APR_ICONV_PATH="C:\Program Files\Subversion\iconv"
COMMONPROGRAMFILES="C:\Program Files\Common Files"
COMPUTERNAME="JIMMY-2000"
COMSPEC="C:\WINNT\system32\cmd.exe"
DIRCMD="/o"
HOMEDRIVE="C:"
HOMEPATH="\Documents and Settings\LeeJimmy"
LOGONSERVER="\\FP-SERVER"
NUMBER_OF_PROCESSORS="1"
OS="Windows_NT"
OS2LIBPATH="C:\WINNT\system32\os2\dll;"
PATH="c:\oracle\ora81\bin;C:\Program Files\Oracle\jre\1.1.7\bin;C:\Perl\bin\;C:\
WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\Program Files\Microsoft SQL Se
rver\80\Tools\BINN;C:\Python23;C:\Program Files\Symantec\pcAnywhere\;C:\cygwin\b
in;C:\cygwin\usr\X11R6\bin;C:\PROGRA~1\GNU\WINCVS~1.3\CVSNT;C:\apache-ant-1.6.2\
bin;C:\Program Files\UltraEdit;C:\Program Files\Subversion\bin"
PATHEXT=".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH"
PROCESSOR_ARCHITECTURE="x86"
PROCESSOR_IDENTIFIER="x86 Family 6 Model 8 Stepping 6, GenuineIntel"
PROCESSOR_LEVEL="6"
PROCESSOR_REVISION="0806"
PROGRAMFILES="C:\Program Files"
PROMPT="$P$G"
SYSTEMDRIVE="C:"
SYSTEMROOT="C:\WINNT"
TEMP="C:\DOCUME~1\LeeJimmy\LOCALS~1\Temp"
TMP="C:\DOCUME~1\LeeJimmy\LOCALS~1\Temp"
TVDUMPFLAGS="10"
USERDNSDOMAIN="com2b.com"
USERDOMAIN="COM2B"
USERNAME="LeeJimmy"
USERPROFILE="C:\Documents and Settings\LeeJimmy"
WINDIR="C:\WINNT"
 
C:\Documents and Settings\LeeJimmy>


reply to postreply to post
作者 Re:Tomcat 如何跑 CGI ? [Re:proshine_roger]
proshine_roger





發文: 6
積分: 0
於 2005-01-12 14:48 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
以下是我執行的畫面

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
C:\Perl\lib>perl "C:\Tomcat 4.1\webapps\ROOT\WEB-INF\cgi\printenv.pl"
Content-type: text/html
 
ALLUSERSPROFILE="C:\Documents and Settings\All Users"
APPDATA="C:\Documents and Settings\Administrator\Application Data"
CATALINA_HOME="C:\Tomcat 4.1\server\lib;C:\Tomcat 4.1"
CLASSPATH="C:\Tomcat 4.1\common\lib\servlet.jar;C:\Tomcat 4.1\common\lib"
COMMONPROGRAMFILES="C:\Program Files\Common Files"
COMPUTERNAME="ROGER"
COMSPEC="C:\WINNT\system32\cmd.exe"
HOMEDRIVE="C:"
HOMEPATH="\Documents and Settings\Administrator"
JAVA_HOME="C:\j2sdk1.4.2_05"
LOGONSERVER="\\ROGER"
NUMBER_OF_PROCESSORS="1"
OS="Windows_NT"
OS2LIBPATH="C:\WINNT\system32\os2\dll;"
PATH="c:\Perl\bin;C:\j2sdk1.4.2_05;C:\j2sdk1.4.2_05\bin;C:\WINNT\system32;C:\WIN
NT;C:\WINNT\system32\WBEM;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:
\Perl\bin"
PATHEXT=".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH"
PROCESSOR_ARCHITECTURE="x86"
PROCESSOR_IDENTIFIER="x86 Family 15 Model 2 Stepping 7, GenuineIntel"
PROCESSOR_LEVEL="15"
PROCESSOR_REVISION="0207"
PROGRAMFILES="C:\Program Files"
PROMPT="$P$G"
SYSTEMDRIVE="C:"
SYSTEMROOT="C:\WINNT"
TEMP="C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp"
TMP="C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp"
USERDOMAIN="ROGER"
USERNAME="Administrator"
USERPROFILE="C:\Documents and Settings\Administrator"
WINDIR="C:\WINNT"
 
C:\Perl\lib>


reply to postreply to post
心是人類的最大戰場
作者 Re:Tomcat 如何跑 CGI ? [Re:proshine_roger]
hkdennis2k





發文: 1926
積分: 6
於 2005-01-12 18:31 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list

`pause`


沒有人發現嗎......


reply to postreply to post
作者 Re:Tomcat 如何跑 CGI ? [Re:proshine_roger]
proshine_roger





發文: 6
積分: 0
於 2005-01-12 18:42 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
發是發現了,不過....它應該不是 不能跑CGI的主要原因吧!

我現在還是無法跑CGI,很奇怪,即使我重灌!!

還是出現一樣的錯誤

我倒底哪裡出錯了?

先安裝JDK 再安裝Tomcat

將 servlets-cgi.renametojar 改為 servlets-cgi.jar

加入環境變數
1
2
3
CLASSPATH = C:\Tomcat 4.1\common\lib\servlet.jar;C:\Tomcat 4.1\common\lib
JAVA_HOME = C:\j2sdk1.4.2_05
Path += C:\j2sdk1.4.2_05;C:\j2sdk1.4.2_05\bin


改Web.xml 的
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    <servlet>
        <servlet-name>cgi</servlet-name>
        <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
        <init-param>
          <param-name>debug</param-name>
          <param-value>6</param-value>
        </init-param>
        <init-param>
          <param-name>cgiPathPrefix</param-name>
          <param-value>WEB-INF/cgi</param-value>
        </init-param>
        <load-on-startup>5</load-on-startup>
    </servlet>
  
    <servlet-mapping>
        <servlet-name>cgi</servlet-name>
        <url-pattern>/cgi-bin/*</url-pattern>
    </servlet-mapping>


將printenv.pl 放到 WEB-INF\cgi\
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/local/bin/perl
##
##  printenv -- demo CGI program which just prints its environment
##
 
print "Content-type: text/html\n\n";
foreach $var (sort(keys(%ENV))) {
    $val = $ENV{$var};
    $val =~ s|\n|\\n|g;
    $val =~ s|"|\\"|g;
    print "${var}=\"${val}\"\n";
}


重新開机
啟動Tomcat service

127.0.0.1/cig-bin/printenv.pl
就是出現了錯誤訊息
1
java.io.IOException: CreateProcess: perl "C:\Tomcat 4.1\webapps\ROOT\WEB-INF\cgi\printenv.pl" error=2  


告訴我,我哪裡錯了∼∼∼∼


proshine_roger edited on 2005-01-12 18:52
reply to postreply to post
心是人類的最大戰場
作者 Re:Tomcat 如何跑 CGI ? [Re:proshine_roger]
jimmy14

Give me J-Power !



發文: 787
積分: 3
於 2005-01-12 19:32 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
stop Tomcat
進入 cmd
測試 perl "C:\Tomcat 4.1\webapps\ROOT\WEB-INF\cgi\printenv.pl" 是否 OK
打下命令啟動 tomcat
1
C:\j2sdk1.4.2_06\bin\java.exe -jar -Duser.dir="C:\Apache\Tomcat 4.1" -Djava.endorsed.dirs="C:\Apache\Tomcat 4.1\common\endorsed" "C:\Apache\Tomcat 4.1\bin\bootstrap.jar" start

測試 http://127.0.0.1:8080/cgi-bin/printenv.pl 是否 OK


jimmy14 edited on 2005-01-12 19:35
reply to postreply to post
作者 Re:Tomcat 如何跑 CGI ? [Re:proshine_roger]
proshine_roger





發文: 6
積分: 0
於 2005-01-14 11:03 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
謝謝 jimmy 的大力幫忙

小弟已解決了∼

後來我下載ActivePerl 就可以了


reply to postreply to post
心是人類的最大戰場
作者 Re:Tomcat 如何跑 CGI ? [Re:proshine_roger]
yenchechang





發文: 46
積分: 0
於 2007-07-31 15:56 user profilesend a private message to usersend email to yenchechangreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
雖然我也試出來了...但是...
請問為什麼要有
<init-param>
<param-name>executable</param-name>
<param-value>cmd /c</param-value>
</init-param>

而不是
<init-param>
<param-name>executable</param-name>
<param-value>perl.exe</param-value>
</init-param>


reply to postreply to post
» JWorld@TW »  Application Server » Tomcat

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8