2013-09-23 38 views
1

我有一個使用Spring 3.2.2的應用程序。我在Tomcat上運行它。我可以在URL路徑中使用頂級域名嗎?

在應用程序中,我有一個返回JSON的控制器。

如果控制器請求映射包含字符串「.com」,「.org」,「.talk」,我得到HTTP錯誤406

由該請求所標識的資源僅能夠生成具有不能接受的特性 響應的根據請求 「接受」標題。

例子:

這工作得很好:

@RequestMapping(method = RequestMethod.GET, value = "/test.test") 
    public @ResponseBody Map<String, String> test() { 
     Map<String, String> stringMap = new HashMap<String, String>(); 
     stringMap.put("test", "test"); 
     return stringMap; 
} 

這會導致HTTP錯誤406:

@RequestMapping(method = RequestMethod.GET, value = "/test.talk") 
     public @ResponseBody Map<String, String> test() { 
      Map<String, String> stringMap = new HashMap<String, String>(); 
      stringMap.put("test", "test"); 
      return stringMap; 
} 

問題不在於與我嘗試了所有的域名轉載。例如「.net」工作正常。

+0

你應該動態地得到它@運行時間和武官它。 – Ketan

+0

您是否使用瀏覽器?如果是這樣,什麼版本? – DaveRlz

+0

我在Win 7上使用Chrome 29.0.1547.66 m版本。此問題也在Firefox 12 –

回答

4

我遇到了與上述相同的問題。我的應用程序在Jetty中工作,但不在Tomcat中。然而,在我的情況下,這個呼叫從未到達過Spring控制器。

因此,如果您也是這種情況,那麼這可能是Tomcat配置問題。 Tomcat在文件web.xml中有mime-mapping。刪除com,org等不需要的映射,406應該消失。

從文件中刪除Apache的Tomcat的7.x版/ conf目錄/ web.xml文件如下:

<mime-mapping> 
    <extension>org</extension> 
    <mime-type>application/vnd.lotus-organizer</mime-type> 
</mime-mapping> 

<mime-mapping> 
    <extension>com</extension> 
    <mime-type>application/x-msdownload</mime-type> 
</mime-mapping>. 
+0

中複製。解決此問題的另一種更簡單的方法可能是使用[在此問題中]描述的映射的尾部斜槓(http:// stackoverflow.com/questions/16332092/sp​​ring-mvc-pathvariable-with-dot-is-getting-truncated) 這樣的路徑可能工作/test.talk/ – wassgren

相關問題