0

我必须为一个项目使用 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;
    }
}

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

4

1 回答 1

0

我发现了问题。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

于 2012-09-17T07:12:10.820 回答