RestEasy open html/jsp page

时光总嘲笑我的痴心妄想 提交于 2019-12-24 01:55:18

问题


There is a RestEasy method, which handles @GET requests. How is it possible to open a jsp/html page from that method?

@GET
@Path("/")
public void getMainPage(){
   //... 
}

回答1:


HtmlEasy is a great tool to render jsp files through RestEasy.

@Path("/")
public class Welcome {
    @GET @Path("/welcome/{name}")
    public View sayHi(@PathParm("name") String name) {
        return new View("/welcome.jsp", name);
    }
}

See documents for all options.




回答2:


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.



来源:https://stackoverflow.com/questions/12253086/resteasy-open-html-jsp-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!