Let me just start out by saying I am completely new to Java web apps, so I'm sorry if this is a very basic question.
I am writing an app that has the ability for users to login to an account. The top part of each page contains an info bar (kind of like the top bar in GMail) with something like:
Logged in as <userid> | Settings | Help
Since that part is going to be on every page, it makes sense to me to split that functionality out so I do not duplicate my code.
I did some searching, and found that I could use this:
<jsp:include page="userInfoBar.jsp" flush="true" />
in the middle of another JSP. I got into problems for my userSettings.jsp page though, which also gets some User detail from the database. Not only am I duplicating some code between the 2 JSPs, but I have a feeling that I am doing double the work during the render of the web page.
For example (Pseudo code):
userInfoBar.jsp:
user = getCurrentUser
if ( user ) {
print Logged in as user.userid | Settings | Help
}
userSettings.jsp:
<jsp:include page="userInfoBar.jsp" flush="true" />
user = getCurrentUser
Change settings for user.userid
So in that little example, getCurrentUser gets called twice (I think, unless Java somehow optimizes that).
How can I avoid this duplication of work, but still keep the userInfoBar somewhat separate from each JSP?
Thanks in advance!
Brian