我的表有'n'个列,当我加载HTML页面时,我只需要打印几列,这必须使用angular-js和jsp来完成。
控制器就像这样
var app = angular.module("myapp",[]);
app.controller("usercontroller",
function($scope, $http){ $scope.displayData = function(){
$http.get("retrieve.jsp") .then(function(data){ $scope.names = response.data; });
}
});
retrieve.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*"%>
<%
String connectionURL = "jdbc:mysql://10.113.114.44:3306/test";
Connection con = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(connectionURL, "root", "admin");
}catch ( SQLException e){
out.println("unsuescc");
}
String sql ="";
sql = "select * from service_request_data;" ;
try{
PreparedStatement myStmt = con.prepareStatement(sql);
myStmt.executeUpdate();
out.print("SUCCESS");
}catch(SQLException e)
{
out.print("SQL Error encountered " );
}catch(Exception ex){
out.println("Unable to connect to database"+ex);
}
%>
任何人都可以帮我解决这个问题吗?