小弟在controller层中,做了如下定义
@RestController
@RequestMapping("/userInfo")
public class UserInfoController {
@RequestMapping(value = "/testAjax.html")
@ResponseBody
public String testAjax(HttpServletRequest request,
HttpServletResponse response)
{
try
{
String param = URLDecoder
.decode(request.getParameter("param"), "utf-8").trim()
.toString();
return "ajax请求成功:" + param;
}
catch (UnsupportedEncodingException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
return "false";
}
}
}
然后使用http://localhost:8080/alan-springmvc-web/userInfo/testAjax.html,来访问该servlet,提示404Error.
代码没有问题,URL也没有错。后来仔细想想,应该是web.xml中配置有问题,因为responsebody里面的value对于的地址是以“.html”结尾