有没有一种简便的方法(不使用spring的方法)使RESTeasy返回带有模型的jsp或html页面?我想做一些类似于Spring ModelAndView的事情,在这里我要说/ contacts / loomer并让它在jsp模板中返回一个模拟对象。我看到的所有示例都是针对JSON / XML的。我知道在Jersey您可以使用可见的内容,但我只需要使用RESTeasy内容。
谢谢!
我想要这样的东西(但没有spring modelandview):
@POST
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)
public ModelAndView saveContactForm(@Form Contact contact)
throws URISyntaxException
{
service.save(contact);
return viewAll();
}
最佳答案
好吧,我想出任何有兴趣的人。一旦找到一个例子,这实际上是微不足道的。
@GET
@Path("{eventid}")
@Produces("text/html")
public void getEvent(@Context HttpServletResponse response,
@Context HttpServletRequest request,
@PathParam("eventid") Long eventid) throws ServletException,
IOException {
EventDao eventdao = DaoFactory.getEventDao();
Event event = eventdao.find(eventid);
request.setAttribute("event", event);
request.getRequestDispatcher("eventView.jsp").forward(request, response);
}
关于model-view-controller - RESTeasy并返回带有模型的JSP页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4110146/