CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  Web 开发

applet调用servlet的问题

楼主tedaugust2002(泰德)2005-04-02 17:33:58 在 Java / Web 开发 提问

我写了一个applet,调用servlet但是servlet总是没有相应?  
  applet的代码:  
   
   
  package   testservlet;  
   
  import   java.awt.*;  
  import   java.awt.event.*;  
  import   java.applet.*;  
  import   javax.swing.*;  
  import   java.net.URL;  
  import   java.net.URLConnection;  
  import   java.net.*;  
  import   java.io.DataOutputStream;  
   
  public   class   Applet1   extends   Applet   {  
      private   boolean   isStandalone   =   false;  
      JButton   jButton1   =   new   JButton();  
      JTextField   jTextField1   =   new   JTextField();  
      JTextField   jTextField2   =   new   JTextField();  
   
      //Get   a   parameter   value  
      public   String   getParameter(String   key,   String   def)   {  
          return   isStandalone   ?   System.getProperty(key,   def)   :  
              (getParameter(key)   !=   null   ?   getParameter(key)   :   def);  
      }  
   
      //Construct   the   applet  
      public   Applet1()   {  
      }  
   
      //Initialize   the   applet  
      public   void   init()   {  
          try   {  
              jbInit();  
          }  
          catch(Exception   e)   {  
              e.printStackTrace();  
          }  
      }  
   
      //Component   initialization  
      private   void   jbInit()   throws   Exception   {  
          jButton1.setBounds(new   Rectangle(143,   70,   73,   25));  
          jButton1.setText("jButton1");  
          jButton1.addActionListener(new   Applet1_jButton1_actionAdapter(this));  
          this.setLayout(null);  
          jTextField1.setSelectionStart(11);  
          jTextField1.setBounds(new   Rectangle(107,   137,   177,   21));  
          jTextField2.setBounds(new   Rectangle(110,   175,   179,   24));  
          this.add(jButton1,   null);  
          this.add(jTextField1,   null);  
          this.add(jTextField2,   null);  
      }  
   
      //Get   Applet   information  
      public   String   getAppletInfo()   {  
          return   "Applet   Information";  
      }  
   
      //Get   parameter   info  
      public   String[][]   getParameterInfo()   {  
          return   null;  
      }  
   
      void   jButton1_actionPerformed(ActionEvent   e)   {  
          try   {  
              String   port   =   jTextField1.getText();  
              String   sl   =   "http://localhost:"+port+"/index.jsp";  
              URL   url   =   new   URL(sl);  
              URLConnection   con   =   url.openConnection();  
              con.setUseCaches(false);  
              con.setDoOutput(true);  
              String   strContent   =   "where   are   you   going?";  
              int   fileLength   =   strContent.getBytes().length;  
              con.setRequestProperty("fileLength",Integer.toString(fileLength));  
              DataOutputStream   dataOut   =   new   DataOutputStream(con.getOutputStream());  
              dataOut.write(strContent.getBytes());  
              dataOut.flush();  
              dataOut.close();  
          }  
          catch   (Exception   ex)   {  
          }  
          //URLConnection   con   =   url.openConnection();  
   
      }  
  }  
   
  class   Applet1_jButton1_actionAdapter   implements   java.awt.event.ActionListener   {  
      Applet1   adaptee;  
   
      Applet1_jButton1_actionAdapter(Applet1   adaptee)   {  
          this.adaptee   =   adaptee;  
      }  
      public   void   actionPerformed(ActionEvent   e)   {  
          adaptee.jButton1_actionPerformed(e);  
      }  
  }  
   
  servlet的代码如下:  
  package   testservlet;  
   
  import   javax.servlet.*;  
  import   javax.servlet.http.*;  
  import   java.io.*;  
  import   java.util.*;  
   
  public   class   Servlet1   extends   HttpServlet   {  
      private   static   final   String   CONTENT_TYPE   =   "text/html;   charset=GBK";  
   
      //Initialize   global   variables  
      public   void   init()   throws   ServletException   {  
      }  
   
      //Process   the   HTTP   Get   request  
      public   void   doGet(HttpServletRequest   request,   HttpServletResponse   response)   throws   ServletException,   IOException   {  
          int   fileLength   =   0;  
          String   fileCotent   =   "";  
          byte[]   fcn   =     new   byte[fileLength];  
          DataInputStream   ins   =   new   DataInputStream(request.getInputStream());  
          fileLength   =   Integer.parseInt(request.getAttribute("Content-length").toString());  
            ins.read(fcn);  
            ins.close();  
            fileCotent   =   fileCotent+fcn.toString();  
   
        if(fileCotent.length()==0)   fileCotent   =   "tedtedted";  
          WriteFile   myWritor   =   new   WriteFile();  
          myWritor.setPath("C:\\ted.txt");  
          myWritor.setSomething(fileCotent);  
          myWritor.writeSomething();  
      }  
   
      //Process   the   HTTP   Post   request  
      public   void   doPost(HttpServletRequest   request,   HttpServletResponse   response)   throws   ServletException,   IOException   {  
   
      }  
   
      //Clean   up   resources  
      public   void   destroy()   {  
      }  
  }  
   
  web.xml  
  <?xml   version="1.0"   encoding="ISO-8859-1"?>  
   
  <!DOCTYPE   web-app  
          PUBLIC   "-//Sun   Microsystems,   Inc.//DTD   Web   Application   2.3//EN"  
          "http://java.sun.com/dtd/web-app_2_3.dtd">  
   
  <web-app>  
      <display-name>Welcome   to   Tomcat</display-name>  
      <description>  
            Welcome   to   Tomcat  
      </description>  
   
   
  <!--   JSPC   servlet   mappings   start   -->  
   
          <servlet>  
                  <servlet-name>Servlet1</servlet-name>  
                  <servlet-class>testservlet.Servlet1</servlet-class>  
          </servlet><servlet-mapping>  
                  <servlet-name>Servlet1</servlet-name>  
                  <url-pattern>/servlet1</url-pattern>  
          </servlet-mapping>  
           
           
  <!--   JSPC   servlet   mappings   end   -->  
   
  </web-app>  
  我调用applet上的按钮但是总是servlet没有相应,服务器为tomcat5。0,请大家赐教,谢谢  
   
  问题点数:0、回复次数:1Top

1 楼ocean617(海洋)回复于 2005-04-02 18:34:00 得分 0

http://www.cn-java.com/target/news.php?news_id=721  
  建议看看这个..  
  好像要建立socket   连接..Top

相关问题

  • applet 调用 servlet 问题 ,急
  • Applet 调用servlet的问题
  • 如何从SERVLET中调用APPLET?
  • 如何在SERVLET里调用APPLET??
  • applet调用Servlet一个问题探讨。
  • 在weblogic下,applet调用servlet时,url怎么设置啊?
  • 请教在servlet中调用applet 怎么设置codebase
  • 请教在servlet中调用applet 怎么设置codebase
  • 在线等 applet调用servlet急 高分求救
  • 急!毕业设计:Applet调用Servlet访问数据库的问题。

关键词

  • .net
  • servlet
  • tomcat
  • 调用
  • applet
  • jtextfield
  • jbutton
  • getparameter
  • def
  • import java

得分解答快速导航

  • 帖主:tedaugust2002

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo