This is my servlet code. I want add my json object values into a json array.I used add method for that but I'm getting an error. How to add that object to my array? Is there any mistake in my code?
@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();
}
}
