RESTeasy and Returning to a JSP page with a model

后端 未结 3 1248
感情败类
感情败类 2020-12-01 08:07

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 req

3条回答
  •  臣服心动
    2020-12-01 08:41

    Using org.jboss.resteasy.resteasy-html version 3.0.6.Final you can directly access the HttpServletRequest and inject your own attributes before directing output to a RESTEasy View.

    @GET
    @Path("{eventid}")
    @Produces("text/html")
    public View getEvent(@Context HttpServletResponse response,
                         @Context HttpServletRequest request,
                         @PathParam("eventid") Long eventid){
    
        EventDao eventdao = DaoFactory.getEventDao();
        Event event = eventdao.find(eventid);
    
        request.setAttribute("event", event);
        return new View("eventView.jsp");
    }
    

    This emulates some behavior of the Htmleasy plugin without having to rewire your web.xml.

提交回复
热议问题