Verifying login with Angular Js and JSP

I am creating an angular js - jsp application for which I created a login page, also I created a servlet to retrieve the database and compare username and password. created a login form and passed the values ​​to my angular controller in the login form. now I need to access a servlet that compares the login, how do I pass information to a servlet? I created a factory for it, also I have to use the post method to transfer data.

I insert the code until I execute it.

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 a servlet used to compare login

+6
source share
2 answers

To access the servlet, add the servlet mapping for this servlet in the deployment descriptor file (web.xml).

For instance:

 <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 service using ... / path / test

+1
source

You were unable to add name attributes to the form field, which allows you to use the form validation rule in this angular field.

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 this me only

+1
source

Source: https://habr.com/ru/post/985985/


All Articles