I have been trying to print 5 array list on my jsp page using scriplets in tabular format but I am unable to do so. I would be really glad if someone could suggest what's wrong with my code. In my output page, I am just seeing the heading printed. The data in the arraylist is not printed. Also, I am not seeing any error/exception information displayed.
1)view.jsp(My jsp page)
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="com.AppUtils.*"%>
<%@page import="java.util.ArrayList"%>
<%Utils utils = new Utils(); %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>View Page</title>
</head>
<body>
<form action="registerForm.jsp">
<table border="1">
<tr><td>Cuid</td>
<td>First Name</td><td>Last Name</td>
<td>Mobile</td><td>Desk</td></tr>
<%for(int i=0; i<utils.getCount();i++){%>
<tr>
<td><%out.print(utils.getCuid().get(i));%></td>
<td><%out.print(utils.getFname().get(i));%></td>
<td><%out.print(utils.getLname().get(i));%></td>
<td><%out.print(utils.getMobile().get(i));%></td>
<td><%out.print(utils.getDesk().get(i));%></td>
</tr>
<%} %>
</table>
<input type="submit" value="Register"/>
</form>
</body>
</html>
2)Utils.java(My java class)
package com.AppUtils;
import java.util.ArrayList;
public class Utils {
public ArrayList getCuid() {
return cuid;
}
public void setCuid(ArrayList cuid) {
this.cuid = cuid;
}
public ArrayList getFname() {
return fname;
}
public void setFname(ArrayList fname) {
this.fname = fname;
}
public ArrayList getLname() {
return lname;
}
public void setLname(ArrayList lname) {
this.lname = lname;
}
public ArrayList getMobile() {
return mobile;
}
public void setMobile(ArrayList mobile) {
this.mobile = mobile;
}
public ArrayList getDesk() {
return desk;
}
public void setDesk(ArrayList desk) {
this.desk = desk;
}
ArrayList cuid = new ArrayList();
ArrayList fname = new ArrayList();
ArrayList lname = new ArrayList();
ArrayList mobile = new ArrayList();
ArrayList desk = new ArrayList();
int count;
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
3)ViewServlet.java(servlet where I added the values to all 5 arraylists)
import java.io.*;
import com.AppUtils.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
/**
* Servlet implementation class ViewServlet
*/
public class ViewServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
System.out.println("Logining in..");
// retrieving values entered in form
String uname = (String)request.getParameter("uname");
String pwd = (String) request.getParameter("pwd");
if (uname.equals("admin") && pwd.equals("admin")) {
try {
viewDetails();
System.out.println("Redirecting to view page..");
response.sendRedirect("view.jsp");
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void viewDetails() throws Exception{
System.out.println("Reading Data..");
BufferedReader input = new BufferedReader(new FileReader("H:/Workspace/teamRecordsApp/WebContent/records.txt"));
String record;
String[] split =new String[5];
ArrayList cuid = new ArrayList();
ArrayList fname = new ArrayList();
ArrayList lname = new ArrayList();
ArrayList mobile = new ArrayList();
ArrayList desk = new ArrayList();
int count = 0;
while((record=input.readLine()) != null){
split = record.split(",");
System.out.println("Record is : "+split[0]+","+split[1]+","+split[2]+","+split[3]+","+split[4]);
cuid.add(split[0]);
fname.add(split[1]);
lname.add(split[2]);
mobile.add(split[3]);
desk.add(split[4]);
count = count+1;
}
input.close();
System.out.println("Reading Done...");
Utils utils = new Utils();
utils.setCuid(cuid);
utils.setFname(fname);
utils.setLname(lname);
utils.setMobile(mobile);
utils.setDesk(desk);
utils.setCount(count);
System.out.println("Total records : "+count);
}
}