Handling of dynamic generated records
What I have learnt is to minimize the amount of java codes in the JSP page.
I retrieve a list of records and store it in an ArrayList and write the records in the UI layer which is my jsp page.
example:
<%
for (int i=0; i<list.size(); i++)
{
// print out html table cell coding
// print out actual data
}
%>
Is there anyway which I can reduce the amount of java codes in my UI layer to handle dynamic data generation?
[490 byte] By [
liangtehza] at [2007-11-27 10:55:45]

A way to avoid java scriplets in your JSP page is to use JSTL (you can look it up on the internet).
Also, here is an example of mixing java scriptlets with html code (below).
Note I dont use a java scriptlet to generate the html, for example,
I dont use <%=out.write("<td>")%>.
If you work in Eclipse, eclipse can be configured to highlight the java scriptlet in a different color foreground (say green) so you can more easily tell the difference between the scriptlet code on the page and the html. With JSTL, Eclipse will not do that. For this reason, I personnally perfer to use scriptlets.
Below, arayList contains a list of String[] where each element
is String[row][column].
Example:
String[] x1=
{"data0_0","data0_1"}
{"data1_0","data1_0"}
<table>
<%for int ii=0;arrayList1.size();++ii){ %>
<tr>
<td>
<%=((String[])arrayList1.get(ii))[0]%>
</td>
<td>
<%=((String[])arrayList1.get(ii))[1]%>
</td>
</tr>
<%}%>
</table>
My approach to the problem is to use the servlets to store the html coding ie. table tr,td codes. into a attributes and save it.
At the jsp page using of <%= request.setAttribute() %> to get the data back. Is it a good practise? Please advise.
All html and jsp tags should be in the JSP page only . Your servlet should pass the data (model) to the JSP page for it to display, along with passing any basic instructions such as what sections should be displayed. The JSP page should not contain any business logic. The JSP page will normally put the name/value pair for each textfield, etc in request scope automcatically that the server can read without resorting to the use of <%= request.setAttribute() %>. If you haven't already done so, I suggest reading a good book on JSP (I dont know of one to recommend off hand). Getting info off the internet what JSP is all about probably is not sufficient.