Hi!! I'm using JSP+Servlets+JavaBeans to make a simple application of inventories.
I have created some beans in the servlet that contain the name of a factory , and then i want to get that data in a jsp page.
Since i'm having many names of factories i named the respective beans like this: factory1, factory2. I do this with this code:
String[] factories = CombofactoriesDB.select(); //this method gives me the names of the different factories in an array.
for(int i = 0; i < factories.length; i++){
request.setAttribute("factory" + i, new Factories(factories[i], null));//I "upload" the beans
}
request.setAttribute("numberOfFactories", new Counter(factories.length));//This is the number of factories i've got, and i use a simple class that has only 1 attribute
Then in the JSP Page i have this code:
<jsp:useBean id="numberOfFactories" scope="request" class="Classes.Counter"/>
<%
for(int i = 0; i < numberOfFactories.getCounter(); i++){
%>
<jsp:useBean id="factory<%=i>" scope="request" class="Classes.Factories"/>
<jsp:getProperty name="factory<%=i%>" property="name"/>
<%}
%>
So in the last lines (useBean and getProperty) i want to input the number of the for cycle but i get an error of the generated servlet because it is interpreting the string as factory<%=i%>
not factory0
, factory1
and so on. Hope you can help me THANKS IN ADVANCE