This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
What modifications should be made in test.jsp to make the employee bean accessible within another jsp.
<jsp:useBean ud="employee" class="EmployeeBean"/>
<jsp:getProperty name="employee" property="salary"/>
Correct answer is: modify the code to use the include directive instead of include action.
Explanation is: By default the scope of the bean is page, so the bean will not be available when the include directive is used. Why?
There is a difference in the way the include directive & <jsp:include> standard action work. Include directive actually includes the source of the included file while <jsp:include> standard action includes the response of the included page. You can have a look at the container generated servlets for the JSPs implementing both these options for a deeper understanding.
Joined: Oct 30, 2006
I thought it has something to do with the page scope.
Like Nilesh said, the two include techniques are different. The include directive puts the contents of the included page directly inside of the JSP when it is translated into Java code and compiled. This means that if the included page contains dynamic content, it will never change (because it was evaluated only once). The include standard action includes the page every single time so that dynamic content shows up. So the include directive is better for static content and the include standard action is better for dynamic content.
Because the include directive puts the contents of the file directly inside of the JSP, you can use page scope.
But if using the include standard action, you must use request scope because the included page exists in a separate page scope.