currently im working on the project that require to shows the data from database and im already found a lot of tutorial video but it seems not working therefore i try to post my question here and look for the problem in my code
Model code
public ArrayList<admin> getAllTrain()
{
ArrayList<admin> list = new ArrayList<admin>();
try {
dbConnection conn = new dbConnection();
Connection myConnection = conn.Connection();
String sql = "SELECT * FROM train";
Statement st = myConnection.createStatement();
ResultSet rs = st.executeQuery(sql);
while(rs.next())
{
admin a = new admin();
a.setTid(rs.getString("tid"));
a.setSloc(rs.getString("sloc"));
a.setEloc(rs.getString("eloc"));
a.setStime(rs.getString("stime"));
a.setEtime(rs.getString("etime"));
a.setSdate(rs.getString("sdate"));
a.setEdate(rs.getString("edate"));
a.setStop(rs.getString("stop"));
a.setSeat(rs.getString("seat"));
a.setPrice(rs.getString("price"));
list.add(a);
}
st.close();
myConnection.close();
} catch (SQLException ex) {
Logger.getLogger(admin.class.getName()).log(Level.SEVERE, null, ex);
}
return list;
}
Servlet Code
admin a = new admin();
List<admin> list = a.getAllTrain();
request.setAttribute("list", list);
request.getRequestDispatcher("trainManagement.jsp").forward(request, response);
JSP Code
<form name ="frmShowData" action ="editTrainControl" >
<table border ="1">
<thead>
<tr>
<th colspan ="10"><center><h4><b>Train Details</b></h4></center></th>
</tr>
</thead>
<th>Train ID </th>
<th>Departure Location </th>
<th>Arrival Location </th>
<th>Departure Time </th>
<th>Arrival Time </th>
<th>Departure Date </th>
<th>Arrival Date </th>
<th>Number of Stop </th>
<th>Number of Seat </th>
<th>Price </th>
<c:forEach items ="${requestScope.list}" var="admin">
<tr>
<td><a href = "${pageContext.request.contextPath}/insertTrainControl?tid = ${admin.getTid()}">${admin.getTid()}</a></td>
<td>${admin.getSloc()}</td>
<td>${admin.getEloc()}</td>
<td>${admin.getStime()}</td>
<td>${admin.getEtime()}</td>
<td>${admin.getSdate()}</td>
<td>${admin.getEdate()}</td>
<td>${admin.getStop()}</td>
<td>${admin.getSeat()}</td>
<td>${admin.getPrice()}</td>
</tr>
</c:forEach>
</table>
</form>
when i run the page there is nothing shows in the table and there is no error message in the netbean also.
Aucun commentaire:
Enregistrer un commentaire