2017-04-20 4 views
0
erlaubt ist

Ich erhalte dieses „Nachricht anfordern Methode‚POST‘nicht unterstütztAntrag Methode ‚POST‘ nicht unterstützt Beschreibung Die angegebene HTTP-Methode nicht für die angeforderte Ressource

Beschreibung Die angegebene HTTP-Methode ist nicht für die angeforderte erlaubt . Ressource "

und

mein Controller-Methode ist: -

@RequestMapping(value = "/addtocart/{id}", method = RequestMethod.GET) 
    public ModelAndView addToCart(@PathVariable("id") String id) { 
     log.debug("Starting of the method addToCart"); 
     // get the product based on product id 
     Product product = productDAO.getProductBYID(id); 
     cart.setPrice(product.getPrice()); 
     cart.setProductName(product.getName()); 
     String loggedInUserid = (String) session.getAttribute("loggedInUserID"); 
     if (loggedInUserid == null) { 
      Authentication auth = SecurityContextHolder.getContext().getAuthentication(); 
      loggedInUserid = auth.getName(); 
     } 
     cart.setUserID(loggedInUserid); 
     //It is not required if you given default value while creating the table 
     cart.setStatus('N'); // Status is New. Once it is dispatched, we can 
           // changed to 'D' 

     //To get sequence number, you can do programmatically in DAOImpl 
     //myCart.setId(ThreadLocalRandom.current().nextLong(100, 1000000 + 1)); 


     cartDAO.save(cart); 
     // return "redirect:/view/Home.jsp"; 

     ModelAndView mv = new ModelAndView("redirect:/Home"); 
     mv.addObject("successMessage", " Successfuly add the product to myCart"); 
     log.debug("Ending of the method addToCart"); 
     return mv; 

    } 
+0

Mögliche Duplikat [diese] zu nennen (http://stackoverflow.com/questions/11145884/http-status-405-request-method-post-nicht-unterstützt-spring-mvc). –

+0

versuchen Sie, diese API mit einem POST aufzurufen? Der Methodentyp sollte GET basierend auf dem Controller sein. – gwcoderguy

+0

Wie rufen Sie diese Methode auf? Wie sieht deine URL aus? – yogidilip

Antwort

1

Sie verwenden RequestMethod.GET für addToCart Methode.

  • Änderungsanforderung-Mapping zu: @RequestMapping(value = "/addtocart/{id}", method = RequestMethod.POST)
  • lassen wie es ist und verwenden GET Anfrage Ihre Methode
Verwandte Themen