0

我有一个带有文本框和提交按钮的基本 html 表单我有兴趣创建一个安静的 Web 服务,在其中我将公开 MY EJB 的方法(来自基于搜索的工作应用程序)以从数据库中检索值。我将在我的应用程序的 EJB 方法中使用在文本框中输入的值作为 SQL 查询的 where 子句。

我是新来的宁静服务。我想在单击提交按钮时生成一个 xml 文件有什么建议..?

我使用的 IDE 是 net beans。

4

1 回答 1

0

如果要检索数据,一个简单的GET请求就足够了。

HTML 表单

<form action="/path/to/the/resource" method="GET">
  <input type="text" name="query" id="query"/>
  <input type="submit" value="Submit Query/>
</form>

JAX-RS 资源

@Path("/path/to/the/resource")
public class MyResource {

  @GET
  @Produces("application/xml")
  public Response query(@QueryParam("query") String query) {
    // retrieve values from the database using the query
    MyJaxbAnnotatedDataClass result = ...;
    return Response.ok(result).build();
  }
}

JAXB 注释类

@XmlRootElement
public class MyJaxbAnnotatedDataClass {
  // many fields, getters, setters with JAXB annotations
}
于 2013-08-09T11:54:07.330 回答