6

I am making an angular js - jsp application, for that I have created a login page, also I have created a servlet for fetching database and comparing username and password. created login form and passed values my angular controller on login form submit. now I need to access the servlet that compares the login how do I pass information to servlet ? I have created a factory for that, also I have to use post method for passing datas.

I am pasting code til I have done.

HTML

<div class="container">

        <form name="myForm" novalidate class="col-md-4 col-md-offset-4">
        <h2>{{login.username}}</h2>
            <div class="form-group">
                <input type="email" ng-model="login.username" required class="form-control input-lg" placeholder="Email">
            </div>

            <div class="form-group">
                <input type="password" required ng-model="login.password"  class="form-control input-lg"
                    placeholder="Password">

            </div>

            <div class="form-group">
                <input type="submit" ng-disabled="myForm.user.$dirty && myForm.user.$invalid ||  
myForm.email.$dirty && myForm.email.$invalid"  ng-click="formSubmit(login)" class="btn btn-primary btn-lg btn-block" value="Sign In"/>
                <span><a href="#">Need help?</a></span> <span class="pull-right"><a
                    href="#">New Registration</a></span>
            </div>

        </form>

    </div>

Controller.js

var appController = angular.module('appController', []);


appController.factory('AccountGroup', ['$resource', 'Data', function ($resource, Data) {
  return $resource( 
    {
      query: {
        isArray: true,
        method: 'POST'
      }
    }
  );
}]);

appController.controller('LoginController', ['$scope','$http', function ($scope,$http) {

      $scope.formSubmit = function(item) {
          debugger;
            console.log(item);
          };


}]);

This is my eclipse directory structure

enter image description here

LoginValdiator.java is the servlet used for login comparison

2
  • From your controller function "formSubmit" you need to call your servlet. Something like $http.post('login servlet url', item);. I am not familiar with Java backend but do you know the path to your servlet to perform the login? Commented Apr 26, 2015 at 12:33
  • @shivas actually I am also looking for the path. Commented Apr 27, 2015 at 3:56

2 Answers 2

1

To access a servlet, add servlet mapping for that servlet in the Deployment descriptor file(web.xml).

Eg :

<servlet>
    <servlet-name>servlet1</servlet-name>
    <servlet-class>org.mycompany.test1</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>servlet1</servlet-name>
    <url-pattern>/path/test</url-pattern>
</servlet-mapping>

Here you can access the servelet by .../path/test

Sign up to request clarification or add additional context in comments.

Comments

1

You missed to add name attributes on your form field which enables form validation rule on that field by angular.

Markup

<div class="container">

    <form name="myForm" novalidate class="col-md-4 col-md-offset-4">
        <h2>{{login.username}}</h2>
        <div class="form-group">
            <input type="email" name="email" ng-model="login.username" required class="form-control input-lg" placeholder="Email">
        </div>
        <div class="form-group">
            <input type="password" name="password" required ng-model="login.password" class="form-control input-lg" placeholder="Password">
        </div>

        <div class="form-group">
            <input type="submit" ng-disabled="myForm.user.$dirty && myForm.user.$invalid ||  
myForm.email.$dirty && myForm.email.$invalid" ng-click="formSubmit(login)" class="btn btn-primary btn-lg btn-block" value="Sign In" />
            <span><a href="#">Need help?</a></span> <span class="pull-right"><a
                    href="#">New Registration</a></span>
        </div>
    </form>
</div>

For more information why name attributes are required, You can refer this Answer by me only

2 Comments

thats fine, but I am not looking for frontend validation at this moment.
@ShajeerAhmd but surely it'd help you while doing front end validation'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.