Thursday 19 September 2013

implicit objects: page

  • page is an instance of object
  • And you have one page implicit object for every jsp page,
  • Lets take one scenario, each and every page in your application you want to display some common text on the header and footer region. So instead of having that common text , present in each and every jsp page in your application it would be good design to have that comman header and footer text in a different header.jsp and footer .jsp file and you are going to add that header and footer to each and every page in the application .

In main page we will code like below:

<jsp:include page="/header.jsp"/>
<jsp:include page="/footer.jsp"/>

  • Here Im using jsp:include action to add the header and footer pages in my main page, here we are going to see what are the different actions we have in future classes but now you can make a note that : jusp:include action to a different jsp page in your jsp page ok 
  • So ultimately when the end user sees the page it does not really know that sources for all these  , source for the jsp page coming from different jsp files, all the user knows that only one page.
  • So one of the advantage of this kind of design is that if at all if you want to make any kind of change in either the header or footer regions you don't really have to make changes in each and every page for your application but it would be fine if you just make the change in one place that is either the header.jsp or footer.jsp
  • So making change in one place is nothing but a 1000 of pages . So here the header.jsp will have its own page implicit object( ex: Hello<%=userName%>), the footer.jsp will have its own implicit object( ex: <table><tr>
             <td>Contact Details</td>
            </tr></table>
  • And the rest of the main page will have its own page implicit objects (example<jsp:include page="/header.jsp"/>, <jsp:include page="/footer.jsp"/> )
  •  You  should not worry about the page object because we would rarely use the page object in jsps .

No comments:

Post a Comment