title: I am trying to fetch data from a servlet into a jsp using angularjs. However, the ng-click seems to be not working. What am I doing wrong?
body: <p>Please find my code below : </p>
  
  <p>angulardemo.jsp</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset="ISO-8859-1"&gt;
      &lt;title&gt;AJAX with Servlets using AngularJS&lt;/title&gt;
      &lt;script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"&gt;&lt;/script&gt;
      &lt;script&gt;
          angular.module('myApp', [])
          .controller('MyController', ['$scope', '$http', function($scope, $http) {
            $scope.getDataFromServer = function() {
              $http.get('AngularServlet',function(data) {
                $scope.person=data;
              },function(failure){
                console.log("failed");
              })
            };
  
          }]);
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div ng-app="myApp"&gt;
        &lt;div controller="MyController"&gt;
             &lt;button ng-click="getDataFromServer()"&gt;Fetch data from server&lt;/button&gt;
             &lt;p&gt;First Name : {{person.fname}}&lt;/p&gt;
             &lt;p&gt;Last Name : {{person.lname}}&lt;/p&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>The Servlet code : </p>
  
  <pre><code>package com.controller;
  public class AngularServlet extends HttpServlet 
  {
     private static final long serialVersionUID = 1L;
  
     public AngularServlet() 
     {
  
     }
     protected void doGet(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
        //JSONObject obj = new JSONObject();
  
        try {
  
           PersonalData personData = new PersonalData();
           personData.setFname("Fname");
           personData.setLname("Lname");   
  
           String json = new Gson().toJson(personData);
           response.setContentType("application/json");
           response.getWriter().write(json);
        }
        catch (Exception e) {
           e.printStackTrace();
        }
     }
  }
  </code></pre>
  
  <p>PersonalData is a simple class with the getter and setter methods for fname and lname. Now when I run the angularjsp.demo on the server and click on Get Data From Server Method , nothing happens. I am not sure if the ng-click is working properly in the first place. Am I doing something wrong ? </p>
  
  <p>The web.xml is : </p>
  
  <pre><code>&lt;web-app&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
    &lt;servlet&gt;
      &lt;servlet-name&gt;AngularServlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.controller.AngularServlet&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;AngularServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/AngularServlet&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>Edit 1: I am getting the proper json output on running the servlet manually.</p>