0
我在我的項目中使用Spring MVC,並將用戶請求映射到URI時,出現404錯誤。但有其他控制器,我可以訪問它。訪問404錯誤的彈簧休息
工作控制器
@RequestMapping(value = "groupview.htm", method = RequestMethod.GET)
public String showGroups(
@ModelAttribute("groupRegistrationDTO") GroupRegistrationDTO groupRegistrationDTO,
BindingResult result, Model model,
HttpServletRequest httpServletRequest) {
GroupsResultDTO groupsResultDTO = manageGroupBusiness.getGroups(
groupRegistrationDTO, result, model);
return "showGroups";
}
測試與Java類表示期望的輸出
private static void wsRequest(String jsonInput) {
try {
URL url = new URL("http://localhost:5080/myservlet/groupview.htm");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept","*/*");
conn.setRequestProperty("Authorization", "Basic "
+ getBasicAuthenticationEncoding());
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
conn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
現在我有另一個控制器,其是RESTful服務當我嘗試測試使用海報插件或者通過java網絡URL連接(使用requestmethod post)。我得到404響應代碼。
試圖通過網址訪問:
http://localhost:5080/myservlet/authAndRegDevice.htm
REST服務控制器
@RequestMapping(value = "authAndRegDevice.htm", method = RequestMethod.POST)
@ResponseBody
public String authenticateAndRegisterDevice(
@RequestBody String notificationJsonRequest){
return "success";
}
爲什麼會第二控制器給予404錯誤,而第一個工作。 有人可以幫我擺脫這個問題
你發送一個JSON作爲請求體,因爲當你調用HTTP的第二個電話://本地主機:5080/myservlet/authAndRegDevice.htm?和;最後是那個偶然還是你調用同一個url? – shazin 2014-09-11 03:41:04
你註冊了第二種方法的bean控制器嗎? – dieend 2014-09-11 04:00:49
@shazin:是的,我發送的json輸入作爲請求正文我dint得到關於相同的URL的第二個問題 – pathfinder 2014-09-11 04:05:34