I am trying to make a simple ajax call. No matter what I do, it always executes a block of errors. I have sysout in doPost that never hits. Someone please tell me what I'm doing wrong. Here is my code.
Javascript ----
$.ajax({ url: "GetBulletAjax", dataType: 'json', success: function(data) { alert("success"); }, error: function(jqXHR, textStatus, errorThrown) { alert(jqXHR+" - "+textStatus+" - "+errorThrown); } });
Java ----
public class GetBulletAjax extends HttpServlet { private static final long serialVersionUID = 1L; public GetBulletAjax() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("made it to servlet"); PrintWriter out = response.getWriter(); User user = (User) request.getSession().getAttribute("user"); int userId = user.getId(); List<Bullet> bullets; BulletDAO bulletdao = new BulletDAOImpl(); try { bullets = bulletdao.findBulletsByUser(userId); Gson gson = new Gson(); String json = gson.toJson(bullets); System.out.println(json); out.println(json); out.close(); } catch (SQLException e) {
web.xml ----
<servlet> <servlet-name>GetBulletAjax</servlet-name> <servlet-class>bulletAjax.GetBulletAjax</servlet-class> </servlet> <servlet-mapping> <servlet-name>GetBulletAjax</servlet-name> <url-pattern>/GetBulletAjax</url-pattern> </servlet-mapping>
source share