【问题标题】:error: invalid type for JAX-RPC structure: jspf.common.ForumPost错误:JAX-RPC 结构的类型无效:jspf.common.ForumPost
【发布时间】:2012-09-17 06:41:10
【问题描述】:

我必须使用 JAX-RPC 为一个项目创建一个 Web 服务,并且在尝试编译它时得到 error: invalid type for JAX-RPC structure: jspf.common.ForumPost。我们必须使用 JDK 5 和 J2EE 1.4。我正在使用带有 JAX-RPC 插件和 Glassfish v1 支持插件的 Netbeans 7.0 来使用 Application Server PE 9 作为我的容器。

这是我的课:

package jspf.common;

import java.sql.Date;


public class ForumPost extends java.lang.Object implements java.io.Serializable {

    private String poster;
    private String content;
    private int topic_id;
    private int post_id;
    private Date time;

    /**
     * Creates a new ForumPost object.
     * @param poster The username of the user that posted the post.
     * @param content The body/content of the post.
     * @param topic_id The topic ID that this post replies to.
     * @param post_id This post's ID.
     */
    public ForumPost() {
    }

    public ForumPost(int post_id, int topic_id, String poster, String content, Date time) {
        this.poster = poster;
        this.content = content;
        this.topic_id = topic_id;
        this.post_id = post_id;
        this.time = time;
    }

    public Date getTime() {
        return time;
    }

    public String getContent() {
        return content;
    }

    public int getPost_id() {
        return post_id;
    }

    public String getPoster() {
        return poster;
    }

    public int getTopic_id() {
        return topic_id;
    }
}

是的,很遗憾,我不得不使用这项旧技术。

我在另一个班级遇到了类似的问题,但似乎可以通过删除其中的 ArrayList 来解决,但我实际上需要 ArrayList

为什么会出现这个错误?

编辑:我去掉了所有对 java.sql.Date 的引用,如下:

package jspf.common;

public class ForumPost extends java.lang.Object implements java.io.Serializable {

    private String poster;
    private String content;
    private int topic_id;
    private int post_id;
    private long time;

    /**
     * Creates a new ForumPost object.
     * @param poster The username of the user that posted the post.
     * @param content The body/content of the post.
     * @param topic_id The topic ID that this post replies to.
     * @param post_id This post's ID.
     */
    public ForumPost() {
    }

    public ForumPost(int post_id, int topic_id, String poster, String content, long time) {
        this.poster = poster;
        this.content = content;
        this.topic_id = topic_id;
        this.post_id = post_id;
        this.time = time;
    }

    public long getTime() {
        return time;
    }

    public String getContent() {
        return content;
    }

    public int getPost_id() {
        return post_id;
    }

    public String getPoster() {
        return poster;
    }

    public int getTopic_id() {
        return topic_id;
    }
}

我仍然遇到同样的错误。我不明白问题是什么。

【问题讨论】:

    标签: java web-services jax-rpc


    【解决方案1】:

    我发现了问题。 J2EE 1.4 文档中定义的值类型必须包含 getter 和 setter 方法,我的类只包含 getter 方法。

    值类型

    值类型是一个类,它的状态可以在客户端和客户端之间传递 远程服务作为方法参数或返回值。例如, 在大学图书馆的申请中,客户可能会打电话给 具有名为 Book 的值类型参数的远程过程,一个类 包含 Title、Author 和 Publisher 字段。

    要被 JAX-RPC 支持,值类型必须符合以下条件 规则:

    • 它必须有一个公共的默认构造函数。
    • 不得(直接或间接)实现 java.rmi.Remote 接口。
    • 其字段必须支持 JAX-RPC 类型。

    值类型可以包含公共、私有或受保护的字段。这 值类型的字段必须满足以下要求:

    • 公共字段不能是最终的或临时的。
    • 非公共字段必须有相应的 getter 和 setter 方法。

    来源:http://docs.oracle.com/javaee/1.4/tutorial/doc/JAXRPC4.html#wp130601

    【讨论】:

      猜你喜欢
      • 2013-06-09
      • 2016-12-21
      • 1970-01-01
      • 2019-03-15
      • 1970-01-01
      • 2012-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多