我在这个Curd Operations Link中找到了这个例子,当我将它集成到我的应用程序数据时没有绑定到表
但是当我运行jsp文件时,它会显示一个对话框
我错了。
这里我使用的是SqlServer数据库
Apr 03, 2017 1:19:16 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:BatchManagementSystems' did not find a matching property.
Apr 03, 2017 1:19:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/9.0.0.M18
Apr 03, 2017 1:19:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Mar 8 2017 15:20:57 UTC
Apr 03, 2017 1:19:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 9.0.0.0
Apr 03, 2017 1:19:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Windows 8.1
Apr 03, 2017 1:19:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 6.3
Apr 03, 2017 1:19:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
Apr 03, 2017 1:19:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: C:\Program Files\Java\jdk1.8.0_121\jre
Apr 03, 2017 1:19:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_121-b13
Apr 03, 2017 1:19:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Apr 03, 2017 1:19:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: D:\JavaProjects\.metadata\.plugins\org.eclipse.wst.server.core\tmp2
Apr 03, 2017 1:19:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: D:\apache-tomcat-9.0.0.M18
Apr 03, 2017 1:19:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=D:\JavaProjects\.metadata\.plugins\org.eclipse.wst.server.core\tmp2
Apr 03, 2017 1:19:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=D:\apache-tomcat-9.0.0.M18
Apr 03, 2017 1:19:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=D:\JavaProjects\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps
Apr 03, 2017 1:19:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=D:\apache-tomcat-9.0.0.M18\endorsed
Apr 03, 2017 1:19:16 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Apr 03, 2017 1:19:16 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.8.0_121\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:/Program Files/Java/jdk1.8.0_121/bin/../jre/bin/server;C:/Program Files/Java/jdk1.8.0_121/bin/../jre/bin;C:/Program Files/Java/jdk1.8.0_121/bin/../jre/lib/amd64;C:\Program Files\Java\jdk1.8.0_121\bin;.;;C:\Users\Lakshmich\Desktop;;.
Apr 03, 2017 1:19:20 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-89"]
Apr 03, 2017 1:19:21 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Apr 03, 2017 1:19:21 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Apr 03, 2017 1:19:21 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Apr 03, 2017 1:19:21 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 7144 ms
Apr 03, 2017 1:19:21 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Apr 03, 2017 1:19:21 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/9.0.0.M18
Apr 03, 2017 1:19:23 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Apr 03, 2017 1:19:23 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [http-nio-89]
Apr 03, 2017 1:19:23 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [ajp-nio-8009]
Apr 03, 2017 1:19:23 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2689 ms
JSP:
<script type="text/javascript">
$(document).ready(function() {
$('#UserRegistration').jtable({
title : 'User Registration',
paging: false, //Enable paging
//pageSize: 3, //Set page size (default: 10)
actions : {
listAction: 'Controller?action=list',
// createAction:'Controller?action=create',
updateAction: 'Controller?action=update',
deleteAction: 'Controller?action=delete'
},
fields : {
UserId : {
title : 'UserId Id',
//sort :true,
//width : '30%'
},
FirstName : {
title : 'FirstName',
//width : '30%',
edit : true
},
LastName : {
title : 'LastName',
//width : '30%',
edit : true
},
MiddleName : {
title : 'MiddleName',
//width : '30%',
edit : true
},
EmailID : {
title : 'EmailID',
//width : '30%',
edit : true
},
Role : {
title : 'Role',
//width : '20%',
edit : true
},
EmployeeId:{
title:'Employee Id',
//width:'20%',
edit:true
}
}
});
$('#UserRegistration').jtable('load');
});
</script>
遵循控制器列表方法
String action = request.getParameter("action");
List<UserRegistration> UsertList = new ArrayList<UserRegistration>();
Gson gson = new GsonBuilder().setPrettyPrinting().create();
//String jsonArray = gson.toJson(JSONROOT);
response.setContentType("application/json");
HashMap<String, Object> JSONROOT = new HashMap<String, Object>();
if(action.equals("list")){
try{
//Fetch Data from User Table
UsertList=dao.getAllUsers();
//Return in the format required by jTable plugin
JSONROOT.put("Result", "OK");
JSONROOT.put("Records", UsertList);
// Convert Java Object to Json
String jsonArray = gson.toJson(JSONROOT);
System.out.println(jsonArray);
response.getWriter().print(jsonArray);
}catch(Exception ex){
JSONROOT.put("Result", "ERROR");
JSONROOT.put("Message", ex.getMessage());
String error = gson.toJson(JSONROOT);
response.getWriter().print(error);
}
}