On Tomcat 6, home.jsp
is translated to the Servlet code:
java.lang.String username = null;
synchronized (application) {
username = (java.lang.String) _jspx_page_context.getAttribute("username",
PageContext.APPLICATION_SCOPE);
if (username == null){
username = new java.lang.String();
_jspx_page_context.setAttribute("username", username,
PageContext.APPLICATION_SCOPE);
}
}
username="Jitendra";
org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response,
"include.jsp", out, false);
Although the behaviour is the same, the exact code generated depends on the application server implementation.
The scope of the local username
variable does not extend into the Servlet that will be generated from include.jsp
. You are not setting the value "Jitendra" into the application scope, only setting the value of the local variable.
As others have pointed out, an immutable String does not make a very good bean.