//Below is my servlet called HtmlTable. I am trying to implement shopping cart like functionality here. addingItems is another class that puts elements in a ArrayList. Whenever I add something from website I want AJAX request to just call the method jusAdding() not the processRequest method. so that when sufficient items are added to the ArrayList I can print it on the screen by calling aI.getItems() which will happen automatically when simply call the servlet. Is it possible?? If yes how should I write the URL in AJAX request.
public class HtmlTable extends HttpServlet {
addingItems aI = new addingItems();
public void jusAdding(HttpServletRequest request, HttpServletResponse response){
aI.addItemsInCart(request, response);
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
List<itemsCart> itemsInCart = aI.getItemsInCart();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet HtmlTable</title>");
out.println("</head>");
out.println("<body>");
//whatever content is in the itemsInCart will be displayed here in body tag
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
}
//forgive me if I am not clear. Let me know I'll update as per reader convenience.