Is it possible to have a jsp page determine which bean to use at run time?

Mad Man

The above scenario can be implemneted but not through jsp:useBean element. Checkout the following example which will instantiate the bean based on the condition.

<% 
String stateCode = request.getParameter("state");
%>

<%

if ( stateCode.equals("CA") )
{
	Bean1 bean1Obj = new Bean1();
%>
<%= bean1Obj.sayHello() %>

<%
}
else
{
	Bean2 bean2Obj = new Bean2();	
%>
<%= bean2Obj.sayHello() %>
<%
}
%>
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


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

 

 

About | Sitemap | Contact