【问题标题】:Java GWT - Celltable and RPCJava GWT - Celltable 和 RPC
【发布时间】:2014-02-19 11:33:45
【问题描述】:

我遇到了 RPC 问题,因此无法进行 seri. RPC 中的静态类

我在我的 : ...Impl.java 中得到了这个

public static class dateils2  {
    private final String be;
    private final String name;

        public dateils2(String name, String be) {
          this.name = name;
          this.be= be;
        }
      }

它抛出:

类型 'com.mi.hu.server.TestImpl$dateils2' 未包含在可由此 SerializationPolicy 序列化的类型集中,或者无法加载其 Class 对象。出于安全考虑,此类型不会被序列化。: instance = com.mi.hu.server.server.TestImpl$dateils2@33cb8da5

我想将 Celltable 的数据作为 Return typ.(mi) 这是我的完整代码:

@SuppressWarnings("serial")
public class TestIml extends RemoteServiceServlet implements TestService{
 public static class dateils2  {
        private final String bestellung;
       // private final Date datum;
        private final String name;

        public dateils2(String name, String bestellung) {
          this.name = name;
          //this.datum = datum;
          this.bestellung = bestellung;
        }
      }


Connection con=null;
Statement st=null;
ResultSet rs=null;
String query;
public ArrayList<dateils2> mi = new ArrayList<dateils2>();
String url="jdbc:sqlserver://hp-compaq;instanceName=E;databaseName=Ba";




 public void call()
 {
       try
       {
             Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
       }
       catch(ClassNotFoundException e)
       {
             System.out.print(e.getMessage());
       }
       try
       {
             con=DriverManager.getConnection(url, "f", "f");
             st=con.createStatement();
       }
       catch(SQLException e)
       {
             System.out.println(e.getMessage());
       }
 }
 /**
  * Query
  */




@Override
public ArrayList show() {

    call();

        try
          {
          rs = st.executeQuery("SELECT * FROM BES");


            while(rs.next()){
                mi.add( new dateils2(rs.getString("NA"), rs.getString("BS")));
            }


            con.commit();
          }
          catch (Exception e)
          {
            System.err.println("Error: " + e.getMessage());
            e.printStackTrace();
          }
          finally {

              try {
                        con.close();
                  } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                  }
            }






    // TODO Auto-generated method stub
    return mi;
}

}

【问题讨论】:

    标签: gwt rpc celltable


    【解决方案1】:

    dateils2 不可序列化,因为:

    • 它没有零参数构造函数(和非final 字段)或CustomFieldSerializer
    • 它没有实现Serializable
    • 它在您的 server 包中,这可能在客户端代码中不可见(您通常会将 DTO 放在 shared 包中,或者可能放在 client 包中;假设您遵循 GWT 项目布局约定)

    http://www.gwtproject.org/doc/latest/DevGuideServerCommunication.html#DevGuideSerializableTypes

    【讨论】:

    • 所以我将其编辑为:public class dateils2 implements Serializable{ String bestellung;字符串名称; }
    • 为什么要删除static 关键字?内部类是不可序列化的,因为您必须有一个包含它们的类的实例来实例化它们。哦,还有,你的类是否可以从客户端代码中看到? (服务器端代码,例如 servlet,一般不会,因为它不能转译成 JavaScript)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多