title: java spring MVC, REST Delete method after clicked a link
body: <p>I am creating a web page that allows the user to add new addresses, delete, and update the address list. My "add new address" is working, however "delete address" is not working.</p>
  
  <p>Please check below my interface design for better understanding, help would be appreciated.</p>
  
  <p>This is my working code for "add new address", and also the non working "Delete address" code.</p>
  
  <p>In Controller:</p>
  
  <pre><code> @RequestMapping(value = "/addressBook", method = RequestMethod.GET)
          public Object AddressBook(HttpSession session) throws Exception {
              try{
                  String memberId= (String) session.getAttribute("memberId");
                  String addressId = (String) session.getAttribute("addressId");
                  List&lt;Address&gt; addresses = memberService.detail(memberId).getAddresses();
                  return new ModelAndView("account/addressBook").addObject("addressList", addresses);
              } catch (Exception e) {
  
                  return new ModelAndView("account/addressBook")
                  .addObject("error", "No address book found");
  
              }
  
          }
  
          @RequestMapping(value = "/addNewAddress", method = RequestMethod.GET)
          public Object AddNewAddress() {
              return "account/addNewAddress";
  
          }
          @RequestMapping(value = "/addNewAddress", method = RequestMethod.POST)
          public Object AddNewAddress(@ModelAttribute AddAddress addAddress, HttpSession session, RedirectAttributes redirectAttributes) {
  
              try {
                  String memberId = (String )session.getAttribute("memberId");
                  AddressDetail address1 = memberService.add(addAddress, memberId);
                  session.setAttribute("addressId", address1.getId());
  
                  return "redirect:/addressBook";
  
              } catch (Exception e) {
  
                  return new ModelAndView("member/addNewAddress")
                          .addObject("addressList", addAddress)
                          .addObject("error", e.getMessage());
              }
          }
   @RequestMapping(value="/deleteAddress" , method =RequestMethod.DELETE )
      public Object DeleteAddress(HttpSession session) throws Exception {
  
              String addressId = (String) session.getAttribute("addressId");
              String memberId = (String) session.getAttribute("memberId");
              AddressDetail addressDetail = memberService.deleteAddress(memberId, addressId);
  
              return new ModelAndView("account/addressBook")
                      .addObject("success", "Address Deleted")
                      ;
              // "redirect:/addressBook";
  
  
      }`
  </code></pre>
  
  <p>HTML Page:</p>
  
  <pre><code>    &lt;div class="8u 12u(5)"&gt;
       &lt;div class="table-wrapper"&gt;
        &lt;h4&gt;Address Book&lt;/h4&gt;
  
      {{#addressList}}
      &lt;address&gt;
       {{street1}}, {{street2}}&lt;br&gt;
      {{district}},{{cityTown}}&lt;br&gt;
   {{postCode}}, {{provinceState}},&lt;br&gt;
     {{countryCode}}&lt;br&gt;
      &lt;br&gt;
     &lt;a href="/editAddress"&gt;Edit&lt;/a&gt; &amp;nbsp &lt;a class="confirm" href="/deleteAddress"&gt;Delete&lt;/a&gt;
     &lt;hr&gt;
    &lt;/address&gt;
    {{/addressList}}
     &lt;/div&gt;
    &lt;a href="/addNewAddress"&gt;&lt;b&gt;Add New Address&lt;/b&gt;&lt;/a&gt;
     &lt;/div&gt;
  </code></pre>
  
  <p>Member Service:</p>
  
  <pre><code>public AddressDetail add(AddAddress addAddress, String memberId) throws Exception {
      Address address = new Address.Builder()
              .setStreet1(addAddress.getStreet1())
              .setStreet2(addAddress.getStreet2())
              .setCityTown(addAddress.getCityTown())
              .setDistrict(addAddress.getDistrict())
              .setProvinceState(addAddress.getProvinceState())
              .setPostCode(addAddress.getPostCode())
              .setCountryCode(addAddress.getCountryCode())
              .build();
  
      RestRequest request = RestRequest.newBuilder()
              .url("/member/" + memberId + "/address")
              .post(address);
  
      Address response = restClient.execute(configuration.serviceMemberName(), request, Address.class).body();
  
      AddressDetail addressDetail = new AddressDetail();
  
      addressDetail.setId(response.getId());
      addressDetail.setDistrict(response.getDistrict());
      addressDetail.setStreet1(response.getStreet1());
      addressDetail.setStreet2(response.getStreet2());
      addressDetail.setCityTown(response.getCityTown());
      addressDetail.setProvinceState(response.getProvinceState());
      addressDetail.setPostCode(response.getPostCode());
      return addressDetail;
  }
  
  
  public AddressDetail addressDetail(String memberId, String addressId) throws Exception {
  
      RestRequest request = RestRequest.newBuilder()
              .url("/member/" + memberId + "/address/" + addressId)
              .get();
  
      Address response = restClient.execute(configuration.serviceMemberName(), request, Address.class).body();
  
      AddressDetail addressDetail = new AddressDetail();
      addressDetail.setId(response.getId());
      addressDetail.setStreet1(response.getStreet1());
      addressDetail.setStreet2(response.getStreet2());
      addressDetail.setDistrict(response.getDistrict());
      addressDetail.setCityTown(response.getCityTown());
      addressDetail.setCountryCode(response.getCountryCode());
      addressDetail.setPostCode(response.getPostCode());
      addressDetail.setProvinceState(response.getProvinceState());
  
  
  
      return addressDetail;
  }
   public AddressDetail deleteAddress(String memberId, String addressId) throws Exception {
      RestRequest request = RestRequest.newBuilder()
              .url("/member/" + memberId + "/address/" + addressId)
              .delete();
  
      Address response = restClient.execute(configuration.serviceMemberName(), request, Address.class).body();
  
      AddressDetail addressDetail = new AddressDetail();
      addressDetail.setId("");
      addressDetail.setStreet1("");
      addressDetail.setStreet2("");
      addressDetail.setDistrict("");
      addressDetail.setCityTown("");
      addressDetail.setCountryCode("");
      addressDetail.setPostCode("");
      addressDetail.setProvinceState("");
  
  
  
      return addressDetail;
  
  }
  </code></pre>