我有一个通过我的jdbc的对象类,我希望在客户登录时显示所有订单。
我的数据库中有一个类可以访问所有订单:
public static ArrayList<OrderSample> showOrders() throws ClassNotFoundException, SQLException, LoginSampleException {
try {
ArrayList<OrderSample> order = new ArrayList();
Connection con = Connector.connection();
String SQL = "SELECT * from useradmin.users";
Statement statement = con.createStatement();
ResultSet rs = statement.executeQuery(SQL);
while(rs.next()){
int id = rs.getInt("idorder");
int height = rs.getInt("height");
int length = rs.getInt("length");
int width = rs.getInt("width");
OrderSample o = new OrderSample(height, length, width);
order.add(o);
}
return order;
} catch (ClassNotFoundException | SQLException ex) {
throw new LoginSampleException(ex.getMessage());
}
}
}
然后我有一个servlet方法将信息放到会话对象中,从命令超类来处理所有请求:
public class Employee extends Command {
@Override
String execute(HttpServletRequest request, HttpServletResponse response) throws LoginSampleException {
try {
ArrayList<OrderSample> orders =UserMapper.showOrders();
request.setAttribute("orders", orders);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Employee.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(Employee.class.getName()).log(Level.SEVERE, null, ex);
}
return "employee";
}
当我尝试循环通过订单对象以在我的jsp中显示它们时,它们不会显示
<c: forEach items="${order}" var="order">
<tr>
<td>Order to delete </td>
</tr>
</c:forEach>
答案 0 :(得分:0)
您正在HttpServletRequest
中设置回复对象。您必须适当地设置响应内容类型,然后在响应正文中设置内容。