I wanted to send JSP form values to database through a servlet and receive the results in another JSP. However, I am able to display the complete results that I receive through the database query, but I couldn't split them and display only the value that I want.
DB class snippet:
public ArrayList<String> getTablenodomain()
{
ArrayList<String> ob1 = new ArrayList<String>();
try
{
s = con.prepareStatement("select AU_ID,DOMAIN_ID,SAFE,SAFE from auditstats");
rs = ps.executeQuery();
while(rs.next())
{
ob1.add(rs.getString(1));
ob1.add(rs.getString(2));
ob1.add(rs.getString(3));
ob1.add(rs.getString(4));
}
}
catch(Exception ee)
{
System.out.println("WHERE ARE YOU DOMAIN");
}
return ob1;
}
My servlet snippet :
DBCoding ob3 = new DBCoding();
if (safe.equals("ALL"))
{ ArrayList<String> a3 = new ArrayList<String>();
a3 = ob3.getTablenodomainsd();
request.setAttribute("safe", a3);
}
else
{
ArrayList<String> al3 = new ArrayList<String>();
al3 = ob3.getTable3(safe, domain);
request.setAttribute("safe", al3);
}
RequestDispatcher rd = request.getRequestDispatcher("page2.jsp");
rd.forward(request, response);
Page2.jsp:
<%
ArrayList<String> ob3 = new ArrayList<String>(); %>
<%if(request.getAttribute("safe")!=null)
{
ob3 = (ArrayList<String>)request.getAttribute("safe");
%>
<%for(int j=0;j<ob3.size();j++)
{
%>
<table>
<tr>STEP-DURATION</tr>
<tr><%=ob3.get(j)%></tr>
</table>
<%}
}%>
By this way, I receive the complete data(all columns/rows) and they get displayed in page2.jsp. But how canI get the data individually?