How to read data from server using AngularJS HTTP Get method.

 AngularJS HTTP

AngularJs HTTP is a service($http) used to communicate with the server.

In this tutorial, I am going to show you :

  • Convert servlet data into JSON format.
  • How to read JSON file data from the server using agularJs HTTP Get method.

 Convert servlet data into JSON format.

package mypack;

public class user {
    private String name;
     String email;
    private String pass;

    public user(String name, String email, String pass) { = name; = email;
        this.pass = pass;
    public String getName() {
        return name;

    public void setName(String name) { = name;

    public String getEmail() {
        return email;

    public void setEmail(String email) { = email;

    public String getPass() {
        return pass;

    public void setPass(String pass) {
        this.pass = pass;

Create a Servlet

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
           throws ServletException, IOException, JSONException 
       try (PrintWriter out = response.getWriter()) 
           /* TODO output your page here. You may use following sample code. */
           String name = "demo Data";
           String email = "";
           String pass = "demo_Data";
           user u = new user(name,email,pass);
           JSONObject obj = new JSONObject();
           obj.put("serverOb", u);
          String json = new Gson().toJson(obj);


Now we have data in JSON format on the server, now create an HTML file for view data.


<html ng-app="myApp">
    <meta charset="utf-8">
    <title>Angular.js Example with mysql</title>
    <script src=""></script>
      var app = angular.module('myApp', []);
      app.controller('myCtrl', function ($scope, $http){
            method : 'GET',
            url : 'Main'
        }).then(function mySucc(response){
            $scope.myData =;
            $scope.statuscode = response.status;
  <body ng-controller="myCtrl">
      <tr ng-repeat="x in myData">
        <td>{{ " " " "+x.pass}}</td>





Leave a Comment

Your email address will not be published.