Это мой код сервлета.Я хочу добавить свои значения объекта json в массив json. Я использовал для этого метод add
, но получаю ошибку.Как добавить этот объект в мой массив?Есть ли ошибка в моем коде?
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try {
Session ses = HibernateSession.getSession();
Criteria cr1 = HibernateSession.createCriteria(ses, Product.class);
cr1.add(Restrictions.eq("Status", "Active"));
List<Product> plist = cr1.list();
JSONArray ja1 = new JSONArray();
for (Product product : plist) {
JSONObject jo1 = new JSONObject();
jo1.put("image", product.getProductImages());
jo1.put("name", product.getName());
jo1.put("price", product.getPrice());
ja1.add(jo1);
}
} catch (Exception e) {
e.printStackTrace();
}
}
