RESTeasy并返回带有模型的JSP页面 [英] RESTeasy and Returning to a JSP page with a model

查看:232
本文介绍了RESTeasy并返回带有模型的JSP页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种简便的方法(不使用spring)让RESTeasy返回带有模型的jsp或html页面?我想做一些类似于Spring ModelAndView的事情,在这里我要说/contacts/loomer并让它在jsp模板中返回一个模拟对象.我看到的所有示例都是针对JSON/XML的.我知道在泽西岛,您可以使用可见的内容,但我只需要使用RESTeasy内容.

Is there an easy, not using spring, way to have RESTeasy return a jsp or html page with a model? I want to do something similar to the spring ModelAndView where I have a request to say /contacts/loomer and have it return a mocked up object in a jsp template. All of the examples I see are for JSON/XML. I know in Jersey you can use the viewable, but I need to use only RESTeasy stuff.

谢谢!

我想要这样的东西(但没有spring modelandview):

I want something like this (but without the 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();
   }

推荐答案

好吧,我为感兴趣的人弄清楚了.找到示例后,这实际上是微不足道的.

Okay, I figured it out for anyone who is interested. It was actually fairly trivial once I found an example.

@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);

    }

这篇关于RESTeasy并返回带有模型的JSP页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆