Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8880059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:05:27+00:00 2026-06-14T20:05:27+00:00

//Below is my servlet called HtmlTable. I am trying to implement shopping cart like

  • 0

//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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:05:28+00:00Added an answer on June 14, 2026 at 8:05 pm

    None of your methods are going to be called by the container. You should start with the servlet specification (or at least the HttpServlet javadoc).

    The container calls the service() method of your servlet, which in turn, for HttpServlet dispatches to the method corresponding to the request HTTP method: doGet(), doPost() etc. That’s where you’re supposed to hook your logic (overwrite one of those, or service() itself and put your code there).

    In order to distinguish between a “full page request” and an “AJAX request”, you need the client to include some discriminator in that call: some request parameter with distinct values, a different HTTP method or whatever. Once you have that, in your doGet() method for instance, you can check that discriminator and invoke either justAdd() or processRequest() according to the client request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying a servlet that puts the data into the database:derbi (that comes
I'm trying to work with the below code: import javax.servlet.*; import javax.servlet.http.*; import java.io.*;
Working on a web application and implementing a class called Calculator that calculates certain
I have a simple servlet which looks like like below. Ite uses the Google's
From my website this servlet below gets called number of times and every time
I want to create a servlet method like below. In this method I want
In the code below I make a POST request to a servlet that replies
Below is code to an inherited ComboBox. The issue is that the ComboBox is
Below is the code from internalRegister method of GCMRegistrar class static void internalRegister(Context context,
Below is the code from a plugin I use for sitemaps. I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.