web.xml没错,是不是servlet listener 写错了?

解决方案 »

  1.   

    侦听是这么写的,主要是启动Socket
    package sms
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;public class Listener
        extends HttpServlet implements ServletContextListener,
        ServletContextAttributeListener {
      //Notification that the web module is ready to process requests
      public void contextInitialized(ServletContextEvent sce) {
        new Server()//这个是Socket类
        throw new java.lang.UnsupportedOperationException(
            "Method contextInitialized() not yet implemented.");
      }  //Notification that the servlet context is about to be shut down
      public void contextDestroyed(ServletContextEvent sce) {
        throw new java.lang.UnsupportedOperationException(
            "Method contextDestroyed() not yet implemented.");
      }  //Notification that a new attribute has been added to the servlet context
      public void attributeAdded(ServletContextAttributeEvent scab) {
        throw new java.lang.UnsupportedOperationException(
            "Method attributeAdded() not yet implemented.");
      }  //Notification that an attribute has been removed from the servlet context
      public void attributeRemoved(ServletContextAttributeEvent scab) {
        throw new java.lang.UnsupportedOperationException(
            "Method attributeRemoved() not yet implemented.");
      }  //Notification that an attribute of the servlet context has been replaced
      public void attributeReplaced(ServletContextAttributeEvent scab) {
        throw new java.lang.UnsupportedOperationException(
            "Method attributeReplaced() not yet implemented.");
      }
    }
    请问错在哪里?
      

  2.   

    实现ServletContextAttributeListener这个接口做什么呢?根本就没有作用。必须将throw new java.lang.UnsupportedOperationException(
            "Method contextInitialized() not yet implemented.");
    去掉,否则会抛出异常,并终止执行。这个是常识。
      

  3.   

    throw new java.lang.UnsupportedOperationException(
            "Method contextInitialized() not yet implemented.");这些是jbuilder生成的默认代码,既然你把方法已经有实现了,就要把这行代码注释掉啊。
      

  4.   

    同样的Socket在一台机子是好的,而在另一台运行出现错误,请问如何解决?  
    package  sms;  
     
    import  java.io.*;  
    import  java.net.*;  
    import  java.math.*;  
    import  sun.io.*;  
    import  org.apache.log4j.Logger;  
    import  org.apache.commons.httpclient.*;  
    import  org.apache.commons.httpclient.methods.GetMethod;  
    import  org.apache.commons.httpclient.methods.*;  
    import  org.apache.commons.httpclient.params.HttpMethodParams;  
     
    public  class  SMSServer  
           extends  java.lang.Thread  {  
       private  static  final  int  SERVER_PORT  =  26549;  
       static  Logger  logger  =  Logger.getLogger(SMSServer.class);  
     
       public  SMSServer()  {  
       }  
     
       public  void  run()  {  
           try  {  
               ServerSocket  s  =  new  ServerSocket(SERVER_PORT);  
               while  (true)  {  
                   Socket  socket  =  s.accept();  
                   Thread  t  =  new  CreateServerThread(socket);  
                   t.start();  
               }  
           }  
           catch  (IOException  e)  {  
               e.printStackTrace();  
           }  
     
       }  
     
    //---  创建服务器线程  
       class  CreateServerThread  
               extends  Thread  {  
           private  Socket  client;  
     
           public  CreateServerThread(Socket  s)  throws  IOException  {  
               client  =  s;  
           }  
     
           public  void  run()  {  
               try  {  
                   client.setSoTimeout(60000);  //超时设置为1分钟  
                   InputStream  input  =  client.getInputStream();  
                   OutputStream  output  =  client.getOutputStream();  
                   //定义变量-----------------------------------------------------------------  
                   String  id_origin  =  "0701";  
                   String  pwd_origin  =  "PP0701WW";  
                   String  src  =  null;  
                   String  dest  =  null;  
                   String  msg  =  null;  
                   String  svcID  =  null;  
                   System.out.println("初始id="  +  id_origin);  
                   System.out.println("初始密码="  +  pwd_origin);  
                   byte[]  sercert  =  new  byte[4];  //密钥byte数组  
                   byte[]  b  =  new  byte[1024];  
                   byte[]  c  =  new  byte[9999];  //把每次循环得到的数组重新组合  
                   ByteArray  ba  =  new  ByteArray();  
                   int  totalNum  =  0;  
                   int  num  =  0;  
                   while  (true)  {  
                       num  =  input.read(b);  
                       System.out.println("num="  +  num);  
                       if  (num  ==  -1)  {  
                                                 byte[]  after109  =  new  byte[1024];  
                           byte[]  after109_scercert  =  new  byte[1024];  
                           after109  =  IntByte.getBytes(c,  16,  124);  
                           after109_scercert  =  crpstr(sercert,  after109,  109);  
                           svcID  =  new  String(IntByte.getBytes(after109_scercert,  0,  3));  号码  
                           System.out.println("服务号码="  +  svcID);  
     
                                           break  ;  
                       }  
                       c  =  ba.addByteArray(IntByte.getBytes(b,  0,  num  -  1));  //每次取得的字节数组相加,得到新的字节数组  
                       totalNum  +=  num;  
                       System.out.println("totalnum="  +  totalNum);  
     
                       //-------把企业发送过来的数据包分两次解密,前12个字节解密一次,后109个字节解密一次--------------  
     
                       if  (totalNum  >=  16)  {  
                           sercert  =  IntByte.getBytes(c,  12,  15);  //取得密钥  
                           System.out.println("sercert="  +  new  String(sercert));  
     
                           //--------------------取得合作伙伴编号ID和密码-------------------------  
                           byte[]  idAndPwd  =  IntByte.getBytes(c,  0,  11);  //取得伙伴ID和密码进行一次性解密  
                           byte[]  idAndPwd_scercert  =  crpstr(sercert,  idAndPwd,  12);  
                           String  id  =  new  String(IntByte.getBytes(idAndPwd_scercert,  0,  3));  //取得伙伴ID  
               
                       }  
                   }  
                   input.close();  
                   output.close();  
                   client.close();  
     
               }  
               catch  (IOException  e)  {  
                   e.printStackTrace();  
               }  
     
           }    
       }    
    }  
    问题总出现在  num  =  input.read(b);  
    提示连接断开  
    但是事实上没有断开的,而且在另一台上运行正常的,本地的端口都是打开的,请问是什么原因?在线等候