2012-09-03 75 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。