2011-08-24 48 views
1

我想實現Spring REST方法。我試圖獲取和它的作品:Spring REST DELETE示例錯誤

@RequestMapping(value = "{systemId}", method = RequestMethod.GET) 
    public 
    @ResponseBody 
    Configuration getConfigurationInJSON(HttpServletResponse response, @PathVariable long systemId) throws IOException { 
     if (configurationMap.containsKey(systemId)) { 
      return configurationMap.get(systemId); 
     } else { 
      response.sendError(HttpServletResponse.SC_NOT_FOUND); 
      return null; 
     } 
    } 

然而,當我想實現刪除它沒有。我的方法是:

@RequestMapping(value = "{systemId}", method = RequestMethod.DELETE) 
    public void deleteConfiguration(HttpServletResponse response, @PathVariable long systemId) throws IOException { 
     if (configurationMap.containsKey(systemId)) { 
      configurationMap.remove(systemId); 
      response.setStatus(HttpServletResponse.SC_FOUND); 
     } else { 
      response.sendError(HttpServletResponse.SC_NOT_FOUND); 
     } 

    } 

我的web.xml如下:

MVC-調度 org.springframework.web.servlet.DispatcherServlet

<servlet-mapping> 
    <servlet-name>mvc-dispatcher</servlet-name> 
    <url-pattern>/ui/*</url-pattern> 
</servlet-mapping> 

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value> 
</context-param> 

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

命令工作當我嘗試使用Curl進行GET時:

curl http://localhost:8080/ui/webapp/conf/1 

命令時,我用捲曲嘗試刪除不工作:一段時間以後捲曲後

curl -x delete http://localhost:8080/ui/webapp/conf/1 

第二個命令給出了錯誤:

curl: (7) couldn't connect to host 

有一個在Tomcat的一側沒有錯誤,在調試時它不會進入刪除方法主體。

任何想法?

回答

1

嘗試

curl -X DELETE http://localhost:8080/ui/webapp/conf/1 

大寫DELETE和大寫X

+1

,也許更重要的是: 「用大寫-X」 ...... –

+0

@Daniel Stenberg發明:你說得對,我已經改正/擴展答案 – Ralph