What will happen when I use the same bean id for different JavaBeans in a <jsp:forward> scenario?

Serge Knystautas

In the <jsp:forward> scenario, you are compiling separate JSPs, so using the same id is allowed as you do not have an issue of local script variable names colliding.

However, whether you get the same or different JavaBean instance depends on the scope you set. If you use request, session, or application as your scope, it will find the instance you used on the first page. If you are doing this but attempting to use a different class, you will get a ClassCastException.

However, if you use page as your scope, you will get a different instance and not risk a ClassCastException. Also, if you are using different scopes for the two beans (in page1 you use session and in page2 you use application), it will not find the first bean and you will not risk a ClassCastException.

Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact