title: How to store objects from session to List in Servlet
body: <p>Good day people.</p>
  
  <p>I have really hard question to me which I spent whole day to think of today.
  The first of all whole code you can get on this url <code>:https://github.com/Vadim32/RemoteWebContent</code></p>
  
  <p>Ok, now is the problem:
  I need to make shopping cart of user orders. Where user can order events like: developing software or computer maintenance. 
  So for this purpose I have servlet:</p>
  
  <pre><code>public class EventNewUserServlet extends HttpServlet {
  
  
      //-------------------------Variables------------------------
  
          private static final long serialVersionUID = 1L;
  
          protected WebContentDAOIF webContentDAOIF;
  
  
      //-------------------------Servlet methods------------------  
  
       public void init() {
           /*Getting bean from spring ContextLoaderListener and inject it to webContentDAOIF variable 
             to use webContentDAOIF in this servlet*/
          ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
              webContentDAOIF = context.getBean("webContentDAOImpl", WebContentDAOIF.class);
          }
  
  
  
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
  
              List&lt;UserEvents&gt; userEventsList = new ArrayList&lt;UserEvents&gt;(2); //This list store all user orders 
  
  
  
          }
  }
  </code></pre>
  
  <p>So I have <code>List&lt;UserEvents&gt; userEventsList</code> in doPost method which will store events which user order, like: ComputerMaintenanceEvent or SoftwareDevelopmentEvent, <strong>they are all extended from UserEvents class</strong> </p>
  
  <p>On this jsp page:</p>
  
  <pre><code>&lt;html&gt;
  
          &lt;head&gt;
              &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
              &lt;title&gt;Order event page&lt;/title&gt;
  
              &lt;!-- Bootstrap css responsive--&gt;
              &lt;link href="resources/css/bootstrap.css" rel="stylesheet"&gt;
              &lt;link href="resources/css/bootstrap-responsive.css" rel="stylesheet"&gt;
  
          &lt;/head&gt;
  
          &lt;body&gt;
  
              &lt;!-- JQuery and Bootstrap file--&gt;
              &lt;script src="resources/js/jquery-1.10.2.min.js"&gt;&lt;/script&gt;
              &lt;script src="resources/js/bootstrap.min.js"&gt;&lt;/script&gt;
              &lt;script src="resources/js/jquery.scrollTo.js"&gt;&lt;/script&gt; 
              &lt;script src="resources/js/jquery.nav.js"&gt;&lt;/script&gt;
  
              &lt;h1&gt;New user&lt;/h1&gt;
              &lt;form action="new-user-event" method="post"&gt;
  
                      &lt;input type="hidden" name="userSessionId" value="${userSessionId}"&gt;
  
                  &lt;table align="center"&gt;
  
                      &lt;tr&gt;&lt;td&gt;Event type:&lt;/td&gt;&lt;td&gt;
                          &lt;select name="event_type"&gt;
                              &lt;option&gt;Choose event type&lt;/option&gt;
                              &lt;option&gt;Computer Maintenance Event&lt;/option&gt;
                              &lt;option&gt;Software Development Event&lt;/option&gt;
                          &lt;/select&gt;
                      &lt;/td&gt;&lt;/tr&gt;
                      &lt;tr&gt;&lt;td&gt;Event date:&lt;/td&gt; &lt;td&gt;&lt;input type="text" class="span2" name="user_event_date"&gt;&lt;/td&gt;&lt;/tr&gt;
                      &lt;tr&gt;&lt;td&gt;Event description:&lt;/td&gt; &lt;td&gt;&lt;textarea rows="5" name="description"&gt;&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt;
                      &lt;tr&gt;&lt;td&gt;Additional Info:&lt;/td&gt; &lt;td&gt;&lt;input type="text" class="span2" name="additional_info"&gt;&lt;/td&gt;&lt;/tr&gt;
  
                      &lt;tr&gt;&lt;td&gt;First name:&lt;/td&gt; &lt;td&gt;&lt;input type="text" class="span2" name="first_name"&gt;&lt;/td&gt;&lt;/tr&gt;
                      &lt;tr&gt;&lt;td&gt;Last name:&lt;/td&gt; &lt;td&gt;&lt;input type="text" class="span2" name="last_name"&gt;&lt;/td&gt;&lt;/tr&gt; 
                      &lt;tr&gt;&lt;td&gt;E-male:&lt;/td&gt; &lt;td&gt;&lt;input type="text" class="span2" name="e_male"&gt; &lt;/td&gt;&lt;/tr&gt;
                      &lt;tr&gt;&lt;td&gt;Address:&lt;/td&gt; &lt;td&gt; &lt;input type="text" class="span2" name="address"&gt;&lt;/td&gt;&lt;/tr&gt;
                      &lt;tr&gt;&lt;td&gt;Phone number:&lt;/td&gt; &lt;td&gt; &lt;input type="text" class="span2" name="phone_number"&gt;&lt;/td&gt;&lt;/tr&gt;
  
                      &lt;tr&gt;&lt;td&gt;&lt;input type="submit" value="Regester user"&gt;&lt;/td&gt;&lt;/tr&gt;
  
                  &lt;/table&gt;
  
              &lt;/form&gt;
  
          &lt;/body&gt;
  
      &lt;/html&gt;
  </code></pre>
  
  <p>User will order the actual events(will make orders). </p>
  
  <p><em>So the requirements are:</em></p>
  
  <ul>
  <li><p>I don't want to make another servlet to store object in list and another servlet to store list of events in database.</p></li>
  <li><p>I want to collect objects of events first in session or just add them to list with no servlet(maybe somehow with jsp or javascripts), when user have for example add button on web page and he can add as many events as he wants in the list and after by submit button from form on same jsp page will trigger the actual servlet to save all collected events from list to database?</p></li>
  </ul>
  
  <p>Is it possible to do so or not??</p>
  
  <p>Thank you developers hope you will help me with some great tutorial or documentation to read.</p>