2

So, This is my view

<div>
    <div class="loginDiv">
        <form name="loginForm" ng-submit="validateDetails()" novalidate>
            <div class="userNameDiv">
                <label class="label" for="username">User Name:</label>
                <input type="text" id="username" name="userName" class="input-medium" ng-model="employee.userName" required ng-minlength=5 ng-maximumlength=20/>
            </div>
            <div class="passwordDiv">
                <label class="label" for="password">Password:</label>
                <input type="password" id="password" name="password" class="input-medium" ng-model="employee.password" required />
            </div>

            <button type="submit" class="btn-large">SUBMIT</button>
        </form>
    </div>
</div>

and the controller to the view is

angular.module('employeeApp.controllers')
    .controller('LoginPageController',['$scope','authenticationDataModelService',function($scope,authenticationDataModelService)
    {

        $scope.validateDetails=function(){
            employee={};
            employee.userName=$scope.employee.userName;
            employee.password=$scope.employee.password;
            console.log(employee);
            authenticationDataModelService.validateData(employee);
        }
    }
    ]);

I am sending this employee object to the service file in which i am sending it in a post request(not including the entire service code):

$http.post(this.employeeDataUrl,employee);

and I am sending it to server and the servlet code is

public class LoginService extends HttpServlet{

    public void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {

        PrintWriter printWriter=response.getWriter();
        response.setContentType("text/html");
        String userName = request.getParameter("userName");
        String password = request.getParameter("password");
        EmployeeDAO employee = new EmployeeDAO();
        System.out.println(userName+""+password);
        boolean validateLogin=employee.validateLogin(userName, password);
        if(validateLogin){
            printWriter.println("Login Success");
        }
        else{
            printWriter.println("Login Failed");
        }

    }
}

but i am getting null values here. I am unable to send the values in the employee object from service file in angularjs to the servlet.How could i achieve this??Pardon me if the question is silly...

Pawan Kalyan
  • 583
  • 3
  • 11
  • 19

1 Answers1

4

AngularJS send your "employee" object in JSON, so you can't read this object on server side with your code. You should parse JSON object first.

strelok2010
  • 1,266
  • 8
  • 12
  • 1
    Yes this is the way to go. Look [here](http://stackoverflow.com/questions/19374345/get-parameter-sent-via-jquery-ajax-in-java-servlet/19376331#19376331) for some more detailed code. It is a similar example (POST object) only using jQuery. – Nikos Paraskevopoulos Nov 07 '13 at 08:58