添加以下代码后:
@GET
@Produces({"application/xml", "application/json"})
public WatchList find(@PathParam("id") Integer id) {
WatchList results = em.createNamedQuery("WatchList.findById", WatchList.class)
.setParameter("id", id)
.getSingleResult();
return results;
}
@GET
@Path("{id}")
@Produces(MediaType.TEXT_HTML)
public void findById(
@Context final HttpServletRequest request,
@Context final HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/jsp/AMLManagement.jsp");
request.setAttribute("items", find("id"));
dispatcher.forward(request, response);
}
我收到错误Severe: WebModule[/MavenProjectTest]StandardWrapper.Throwable
org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.
而且:Severe: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.
有谁知道如何解决这个问题?我在上面的代码中做了什么错误导致了这个错误吗?
答案 0 :(得分:0)
好的,我必须添加一个路径,我传递的id不应该是一个字符串,我必须在findId中添加@Pathparam
,我解决了这个问题:
@GET
@Path("{id}")
@Produces({"application/xml", "application/json"})
public WatchList find(@PathParam("id") Integer id) {
WatchList results = em.createNamedQuery("WatchList.findById", WatchList.class)
.setParameter("id", id)
.getSingleResult();
return results;
}
@GET
@Path("{id}")
@Produces(MediaType.TEXT_HTML)
public void findId(@PathParam("id") Integer id,
@Context final HttpServletRequest request,
@Context final HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/jsp/AMLManagement.jsp");
request.setAttribute("items", find(id));
dispatcher.forward(request, response);
}