0

My class in the project is under a package com.project.controller and the name of the servlet class is UpdateDatabaseController. The corresponding code of the web.xml is,

<servlet>
    <servlet-name>UpdateDatabaseController</servlet-name>
    <servlet-class>com.project.controller.UpdateDatabaseController</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>UpdateDatabaseController</servlet-name>
    <url-pattern>/UpdateDB</url-pattern>
  </servlet-mapping>

In the html page, I have a button that is calling a function, updateDatabase(). And the code of the script is:

$scope.updateDatabase = function(){
        $http.get('/UpdateDB').success(function(data) {
            alert("Controller hit");
        });
    };

Whenever I hit the button, the error in the browser log is displayed, that : "NetworkError: 404 Not Found - http://localhost:8080/UpdateDB"

I want that on my button click, the POST method of the servlet class is invoked. But the error is fixed in the browser log. I am unable to solve this situation.

5
  • you miss ProjectName in ur URL localhost:8080/ProjectName/UpdateDB Commented Mar 5, 2015 at 8:59
  • How can I do include that in the URL? Commented Mar 5, 2015 at 9:05
  • as i wrote localhost:8080/ProjectName/Servletmapping Commented Mar 5, 2015 at 9:09
  • I got it correct. But suppose I want to call a particular method in the servlet, shall I append the name of the method behind the URL? Commented Mar 5, 2015 at 9:12
  • Search 4 RestFul webServices that's 'll help check my answer here stackoverflow.com/questions/28431669/spring-mvc-rest-angularjs/… Commented Mar 5, 2015 at 9:26

2 Answers 2

1
$scope.updateDatabase = function(){
        $http.get('http://localhost/YourProject/UpdateDB').success(function(data) {
            alert("Controller hit");
        });
    };

I had the same problem, and fixed it by adding http:// in front of the link.

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

Comments

0

you miss ProjectName in ur URL localhost:8080/ProjectName/UpdateDB

2 Comments

@ Ahmed Adel I added project name in the URL. That s also not working. See my local url localhost:8080/AngularJSAll/03_AjaxCall/3.1_ajax_contoller/ajaxFile.jsp
we are talking here about calling a servlet using angularjs, why you are refer to jsp page

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.