00000003.htm
来自「水木清华BBS」· HTM 代码 · 共 80 行
HTM
80 行
<HTML><HEAD> <TITLE>BBS水木清华站∶精华区</TITLE></HEAD><BODY><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER>发信人: code (dog), 信区: Java <BR>标 题: applet怎样与CGI程序通信 <BR>发信站: BBS 水木清华站 (Wed Aug 6 21:35:16 1997) <BR> <BR>【 在 bust (大脚龙) 的大作中提到: 】 <BR>∶<I> 我的applet要与CGI程序通信,请高手指教. </I><BR>∶<I> 其实,我主要是想我的applet能向http服务器 </I><BR>∶<I> 写文件以及读文件. </I><BR>∶<I> 若能指点applet及CGI的样板程序, </I><BR>∶<I> 当感激涕零. </I><BR> <BR>本人对Java也是新手,Post一个简单程序,莫见笑: <BR> <BR>/*******CGI**************/ <BR>main() <BR>{ <BR> long num; <BR> char d1[25]="counter.txt"; <BR> FILE *fd=fopen(d1,"r"); <BR> fscanf(fd,"%ld",&num); <BR> num++; <BR> fclose(fd); <BR> fd=fopen("counter.txt","w"); <BR> fprintf(fd,"%ld",num); <BR> fclose(fd); <BR> printf("Content-type: text/plain\n\n"); <BR> printf("%07ld\n",num); <BR>} <BR> <BR>/*********applet***********/ <BR>import java.awt.*; <BR>import java.net.*; <BR>import java.io.*; <BR>public class count extends java.applet.Applet <BR>{ <BR> Font fn=new Font("Times Roman",Font.BOLD,24); <BR> String count_str1; <BR> public void init() <BR> { <BR> try { <BR> URL serverURL=new URL("<A HREF="http://202.112.147.194/cgi-bin/count.cgi");">http://202.112.147.194/cgi-bin/count.cgi");</A> <BR> DataInputStream dis; <BR> dis=new DataInputStream(serverURL.openStream()); <BR> count_str1=dis.readLine(); <BR> dis.close(); <BR> } <BR> catch(MalformedURLException mfURLe) <BR> {System.out.println("MalformedURLException:"+mfURLe);} <BR> catch(IOException ioe) <BR> {System.out.println("IOException:"+ioe);} <BR> } <BR> public void paint(Graphics g) <BR> { <BR> g.setFont(fn); <BR> g.setColor(Color.blue); <BR> g.drawString(count_str1,10,50); <BR> } <BR> } <BR> <BR>-- <BR>※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: 202.112.147.198] <BR><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?