开发者

How to better transfer objects between Jersey restful enabled classes to JSP pages

开发者 https://www.devze.com 2023-01-13 05:28 出处:网络
I have this : public class Base { @GET @Path(\"/news/{page_number}\") public Viewable news(@PathParam(\"page_number\") int pageNumber) {

I have this :

public class Base {

    @GET
    @Path("/news/{page_number}")
    public Viewable news(@PathParam("page_number") int pageNumber) {

        NewsParams news_params = new NewsParams();
        news_params.setPageNumber(pageNumber);

        return new Viewable("/news.jsp", news_params);
    }
}

and the news.jsp is :

 开发者_开发百科  ${it.pageNumber}

My question is : What to do (or which is the best way) if a have a lot of objects to transfer from jersey restful classes (which represent the application logic) to the JSP pages (which represent the application view) ?


You could pass a POJO to the Viewable instead. If you were to pass a Customer object with an Address property then you could access the date in your JSP as follows:

${it.firstName}
${it.lastName}
${it.address.street}
${it.address.city}


The way to go is to pass a POJO to the Viewable and use as shown by Doughan above. In addition to that you could also pass around request attributes or via session, though personally I always try to avoid session wherever and whenever possible.

Example of passing request attributes can be found here, Line 56, 57 and 103 will comprise of the example.

0

精彩评论

暂无评论...
验证码 换一张
取 消