AngularJS AJAX调用JAVA中的一个servlet [英] AngularJS AJAX call to a servlet in JAVA

查看:915
本文介绍了AngularJS AJAX调用JAVA中的一个servlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目类是包com.project.controller下和servlet类的名称是UpdateDatabaseController。 web.xml中的相应code是,

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>

在HTML页面中,我有一个按钮,被调用函数,updateDatabase()。和脚本的code是:

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");
        });
    };

每当我按下按钮,将显示在浏览器日志中的错误,即:
NetworkError:404未找​​到 - 的http://本地主机:8080 / updatedb的

我想这对我的点击按钮,servlet类的POST方法被调用。但错误被固定在浏览器中的日志。我无法来解决这种状况。

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.

推荐答案

您在乌拉圭回合网址错过项目名本地主机:8080 /项目名/数据库更新

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

这篇关于AngularJS AJAX调用JAVA中的一个servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆