V
Vittorix
Hi guys,
I retrieve books from a database and put each book with its data into a
bean.
this works well, the beans are called bookBeanBeg1, bookBeanBeg2,
bookBeanBeg3, bookBeanBeg4, etc.
then I retrive the first bean from an JSP page with:
<jsp:useBean id="bookBeanBeg1" type="p4Solution.BookBean" scope="session" />
<jsp:getProperty name="bookBeanBeg1" property="shortDescription"/>
and it works fine.
Now I try to make an automatic retrieval with a for loop.
The for cicle works well in I hardcode for example the id="bookBeanBeg1" and
the name="bookBeanBeg1"
Bu there is some problem in using an expression inside the two declarations,
it gives me an error. it doesn't accept the id the name attributes created
by the expression.
can you please help me fix this? thanks
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h2>Hello HTML beginner!</h2>
<%
int numBooks =
Integer.parseInt(request.getParameter("numBookBeg"));
%>
<%= numBooks %> books available for you.
<br> <br>
<UL>
<%
for (int i=1; i<=numBooks; i++)
{
String bookBeanBeg;
bookBeanBeg = "bookBeanBeg" + i + "";
%>
<br> <br> NOTE: ERROR BELOW
<jsp:useBean id="<%=bookBeanBeg%>"
type="p4Solution.BookBean" scope="session" />
<LI><jsp:getProperty name="<%=bookBeanBeg%>"
property="shortDescription"/>
<% } %>
</UL>
</body>
</html>
I retrieve books from a database and put each book with its data into a
bean.
this works well, the beans are called bookBeanBeg1, bookBeanBeg2,
bookBeanBeg3, bookBeanBeg4, etc.
then I retrive the first bean from an JSP page with:
<jsp:useBean id="bookBeanBeg1" type="p4Solution.BookBean" scope="session" />
<jsp:getProperty name="bookBeanBeg1" property="shortDescription"/>
and it works fine.
Now I try to make an automatic retrieval with a for loop.
The for cicle works well in I hardcode for example the id="bookBeanBeg1" and
the name="bookBeanBeg1"
Bu there is some problem in using an expression inside the two declarations,
it gives me an error. it doesn't accept the id the name attributes created
by the expression.
can you please help me fix this? thanks
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h2>Hello HTML beginner!</h2>
<%
int numBooks =
Integer.parseInt(request.getParameter("numBookBeg"));
%>
<%= numBooks %> books available for you.
<br> <br>
<UL>
<%
for (int i=1; i<=numBooks; i++)
{
String bookBeanBeg;
bookBeanBeg = "bookBeanBeg" + i + "";
%>
<br> <br> NOTE: ERROR BELOW
<jsp:useBean id="<%=bookBeanBeg%>"
type="p4Solution.BookBean" scope="session" />
<LI><jsp:getProperty name="<%=bookBeanBeg%>"
property="shortDescription"/>
<% } %>
</UL>
</body>
</html>