
this my servlet page.. @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response);
DataSource ds=null;
Connection con = null;
PreparedStatement smp = null;
ResultSet rs = null;
try {
Context c =new InitialContext();
ds = (DataSource)c.lookup("jdbc/surevac");
con =ds.getConnection();
ArrayList al=null;
ArrayList Product_List =new ArrayList();
String query = "select * from PRODUCT_LIST";
smp = con.prepareStatement(query);
rs = smp.executeQuery(query);
while(rs.next())
{
al = new ArrayList();
al.add(rs.getInt(1));
al.add(rs.getString(2));
System.out.println("al :: "+al);
Product_List.add(al);
}
request.setAttribute("Product_List",Product_List);
String nextJSP = "Administrotar/Product_list.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
dispatcher.forward(request,response);
con.close();
} catch (Exception e) {
System.out.println("......."+e);
}
}
and this is my jsp page.. <% String bgcolor=""; int count=0; List viewList = new ArrayList(); Iterator viewItr;
if(request.getAttribute("userList")!=null && request.getAttribute("userList")!="")
{
List userList = (ArrayList)request.getAttribute("userList");
Iterator itr = userList.iterator();
while(itr.hasNext())
{
if(count%2==0)
{
bgcolor = "#C8E2D1";
}
else
{
bgcolor = "#EAF8EF";
}
viewList = (ArrayList)itr.next();
int id = Integer.parseInt(viewList.get(0).toString());
viewItr = viewList.iterator();
%>
<tr style="background-color:<%=bgcolor%>;">
<%
while(viewItr.hasNext())
{
%>
<td><%=viewItr.next()%></td>
<%
}
count++;
%>
<td><input type="button" name="edit" value="Edit" style="background-color:#49743D;
font-weight:bold;color:#ffffff;"
onclick="editRecord(<%=id%>);" >
</td>
<td>
<input type="button" name="delete"
style="background-color:#ff0000;
font-weight:bold;;color:#ffffff;"
value="Delete"
onclick="deleteRecord(<%=id%>);"></td>
</tr>
<%
}
}
if(count==0)
{
%>
<tr><td colspan="9" align="center"> </td></tr>
<tr><td colspan="9" align="center">No Record Avaliable</td></tr>
<%
}
%>
it's not working..ple anybody can correct is code.....
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.