2

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(){
   //... 
}
user1588782
  • 293
  • 1
  • 4
  • 6
  • 1
    How about [this](http://stackoverflow.com/q/4110146/1407656)? – toniedzwiedz Sep 03 '12 at 19:34
  • Which dependency should i add to maven project? Adding servlet-api 2.5 doesn't help... – user1588782 Sep 04 '12 at 16:18
  • I don't know, I don't even know what dependencies you have so far. It will be faster if you post a comment on the answer to that question, asking what dependencies are needed. When it comes to JAX-RS, I'm more of a Jersey person. – toniedzwiedz Sep 04 '12 at 20:25

2 Answers2

2

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.

Ali Shakiba
  • 20,549
  • 18
  • 61
  • 88
1

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.

qgicup
  • 2,189
  • 1
  • 16
  • 13