使用角度js在jsp中插入数据而不使用servlet

时间:2017-06-28 05:33:10

标签: javascript angularjs jsp

我刚开始学习AngularJS。对于熟悉AngularJS的人来说,我几乎无法澄清。

以下是我使用AngularJS尝试的代码:

<%@page import="java.sql.Connection"%>
<%@ page import = "java.sql.*" %> 
<!DOCTYPE html>
<html>
    <head>
        <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
        <script>
             window.alert("alert 1");
           var app = angular.module('myApp',[]);
    app.controller('bookController',function(){ 

    $scope.bname = null;
    $scope.bauthor = null;
    $scope.price = null;
    $scope.blanguage=null;
    $scope.insertData=function(bname,bauthor,bprice,blanguage){ 

                window.alert($scope.bname);
        var author=$scope.bauthor;
                window.alert("author"+author);
        var price=$scope.bprice;
                window.alert("price"+price);
        var lang=$scope.blanguage;
                window.alert("lang"+lang);


           <%  
             Class.forName("oracle.jdbc.driver.OracleDriver");
                Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.12.9:1521:ng12c", "xyz", "xyz");
                Statement stmt = conn.createStatement();
                String sql = "insert into sample_angularjs (NAMEE,AGE,ADDRESS1,ADDRESS2) values("+name+","+author+","+price+","+lang+")";
                ResultSet rs = stmt.executeQuery(sql); 
                rs.close();
                conn.close();

           %>


        }
         });
        </script>
    </head>
    <body >
 <form ng-controller="bookController" ng-submit="insertData(bname,bauthor,bprice,blanguage)">
Book Name:-<input type="text" ng-model="bname" />
Book Author:-<input type="text" ng-model="bauthor" />
Book Price:-<input type="text" ng-model="bprice" />
Book Language:-<input type="text" ng-model="blanguage" />
<button type="Submit"/>
</form>
    </body>
</html>

疑惑:

  1. 文本框中的值未传递给js函数。

  2. AngularJS中是否有任何方法可以在不使用servlet的情况下将值从文本框插入数据库?

0 个答案:

没有答案