2012-09-03 79 views
1

有一个RestEasy的方法,它处理@GET请求。如何从该方法打开一个jsp/html页面?RestEasy的打开HTML/JSP页面

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

怎么样[这](http://stackoverflow.com/q/4110146/1407656)? – toniedzwiedz

+0

我应该添加哪个依赖项到maven项目中?添加servlet的API 2.5没有帮助... – user1588782

+0

我不知道,我甚至不知道哪些依赖你有这么远。如果您对该问题的答案发表评论,并询问需要哪些依赖关系,速度会更快。说到JAX-RS,我更像是一个泽西岛人。 – toniedzwiedz

回答

2

HtmlEasy是通过RestEasy的渲染jsp文件一个伟大的工具。

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

documents所有选项。

1

使用org.jboss.resteasy.resteasy-html version 3.0.6.Final您可以直接访问HttpServletRequest和定向输出到的RESTEasy查看之前注入自己的属性。

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

这模拟了Htmleasy插件的一些行为,而无需重新连接您的web.xml。