有点不知所措。我正在通过来自不同JSP页面的ajax调用来调用相同的方法,并且得到了不同的HTTP response
。一个给200,而另一个给400。为什么呢?
到JSP
页之间的唯一区别是level/depth
例
main.jsp is at level localhost/appname/main.htm
other.jsp is at level localhost/appname/myworld/other.htm
双方发布Ajax调用的URL都相同
function getResponse(value) {
$.ajax({
url: '${pageContext. request. contextPath}/posthere/callme.htm',
data: {
valueId: value,
},
type: "POST",
success: function (data) {
if(data == true) {
console.log("Success: ");
} else {
console.log("Failed: ");
}
}
});
}
控制者
@Controller
@RequestMapping(value = "/posthere")
@SessionAttributes({"userSession"})
public class MyController {
@RequestMapping(value = "/callme", method = RequestMethod.POST)
public @ResponseBody
boolean getcalled(@RequestParam("valueId") String valueId,
@ModelAttribute("userSession") UserSession userSession,
HttpServletResponse httpServletResponse) throws IOException {
if(userSession != null) {
//do your magic. Note: This logic is not getting invoked. I have a breakpoint here.
return true;
}
return false;
}
}
最佳答案
检查内容类型。当内容类型为X并且发送的内容与X不相等时,我遇到了这个问题。