0

I'm trying to implement search method in my project and I want to pass the query from the HTML page to the search servlet , I tried so many ways but when I print the value passed to the search servlet I get null,I don't know what is wrong:Is it the way I pass the value from HTML? Or Is it the way I read the value in the Servlet?

Here's what I tried last:

Page.html:

<div class="modal-body">
    <div class="form-group">
        <input ng-model="searchinput" placeholder="search channels, users " ng-change="search()" />&nbsp;
    </div>
</div>

In the Controller that contains the modal:

$scope.search = function() {
    $http.get("http://localhost:8080/ExampleServletv3/SearchServlet",$scope.searchinput)
        .success(function(response) {
            $scope.records = response;
            $scope.result = $scope.records;//this variable will hold the search results
        });
};

SearchServlet.java:

BufferedReader reader = request.getReader();
String query=reader.readLine();
System.out.println(query);

I tried also getParameter("searchinput") but nothing worked.

Can somebody help me please?

Thanks

user6561572
  • 219
  • 3
  • 14
  • I would suggest to read the documentation of $http: https://docs.angularjs.org/api/ng/service/$http, especially of the config object you're supposed to pass as second argument of $http.get (https://docs.angularjs.org/api/ng/service/$http#get, https://docs.angularjs.org/api/ng/service/$http#usage), and especially how to pass GET params using this object. Everything becomes much simpler when you read documentation. – JB Nizet Feb 18 '17 at 07:46
  • @MicD thanks it worked! – user6561572 Feb 18 '17 at 07:51
  • @JB Nizet thank you! – user6561572 Feb 18 '17 at 07:52

0 Answers0