title: How to create twitter bootstrap CRUD with servlets/jsp
body: <p>How do I create CRUD with twitter bootstrap (for frontend inside a jsp file) and servlets/jsp.
  I have not found a good example to guide me.</p>
  
  <ol>
  <li>I want to use twitter bootstrap for frontend - I have a jsp for this.</li>
  <li>list was for showing content that will be displayed in frontend.</li>
  </ol>
  
  <p>The below is a snippet of the level I have reached.</p>
  
  <pre><code>connection = DBConnection.getConnection();
  if (request.getParameter("action") != null) {
  
      List&lt;Content&gt; listContent = new ArrayList&lt;Content&gt;();
      String action = (String) request.getParameter("action");
      Content content = null;
      Gson gson = new Gson();
      response.setContentType("application/json");
  
      if (action.equals("list")) {
          try {
              // Fetch Data from Content Table
              listContent = contentService.getAllContent(connection);
              // Convert Java Object to Json
              JsonElement element = gson.toJsonTree(listContent,
                      new TypeToken&lt;List&lt;Content&gt;&gt;() {
                      }.getType());
              JsonArray jsonArray = element.getAsJsonArray();
              String listData = jsonArray.toString();
  
              listData = "{\"Result\":\"OK\",\"Records\":" + listData
                  + "}";
              response.getWriter().print(listData);
          } catch (Exception ex) {
              String error = "{\"Result\":\"ERROR\",\"Message\":"
                  + ex.getMessage() + "}";
              response.getWriter().print(error);
              ex.printStackTrace();
          }
      } else if (action.equals("create") || action.equals("update")) {
          content = new Content();
          if (request.getParameter("id") != null) {
              int idField = Integer.parseInt(request.getParameter("id"));
              content.setId(idField);
          }
          if (request.getParameter("content") != null) {
              String contentField = (String) request
                  .getParameter("content");
              content.setContent(contentField);
          }
          if (request.getParameter("category") != null) {
              String categoryField = (String) request
                  .getParameter("category");
              content.setCategory(categoryField);
          }
  </code></pre>