【发布时间】:2011-07-05 10:26:03
【问题描述】:
我的 ajax 调用具有 url http://localhost:80/Push/GetContacts?id=23 和以下 servlet 映射:
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/GetContacts*</url-pattern>
</servlet-mapping>
在 ajax 调用上不会调用 servlet。它返回 HTTP 404 not found 响应。我的 ajax 调用的正确 URL 模式是什么?
这里是由于 servlet 而无法正常工作的 ajax 调用。
jQuery.getJSON('http://localhost:8080/Push/GetContacts&callback=?', function(data) {
alert(data.data);
});
小服务程序:
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException{
try{
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.write("{data: helloworld}");
out.close();
}
catch(Exception e){
e.printStackTrace();
}
【问题讨论】: