title: Spring controller - send html as response
body: <p>I have a loaded jsp page with products and addtocart link against it. I am trying to show the cart in a div in the same page. I want to send html as response. This is what i have done. It just returns the string <code>&lt;div&gt;output&lt;/div&gt;</code>. Can someone show me how i should do it.</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>    @RequestMapping(value="/addtocart{id}",  produces = "text/plain;charset=UTF-8")
      @ResponseBody
      public String addToCart(@PathVariable("id") int id, @ModelAttribute("cart") Cart cart,Model model)
      {
          Product product = productService.getProductById(id);
          if (product != null) {
              CartLine line = new CartLine();
              line.setProduct(product);
              line.setQuantity(1);
              productService.updateProduct(product);
          }
          return "&lt;div&gt;output&lt;/div&gt;"; 
      }
  </code></pre>
  
  <p><strong>JSP</strong></p>
  
  <pre><code>&lt;td&gt;&lt;a id="demo4" href="addtocart${product.id}"&gt;Add To Cart&lt;/a&gt; &lt;/td&gt;
  
  $('#demo4').click(function() { 
  
                  $.ajax({    
                  url : '/addtocart{id}',
                  dataType: 'json',
                  contentType: "text/html",
                  type : 'GET',
                  data :{id:id},
                  success : function(response) {
                      $('#output').html(response);
                     }
                   }); 
          }); 
  
  &lt;div id="output" style="display:none"&gt;
             &lt;h2&gt;Cart Content(s):&lt;/h2&gt;
  &lt;/div&gt;
  </code></pre>