Java 如何使用fullCalendar.js从数据库中提取数据,并使用jsp、servlet的
以下是我用jsp编写的一段代码: 完整日历Java 如何使用fullCalendar.js从数据库中提取数据,并使用jsp、servlet的,java,javascript,json,jsp,servlets,Java,Javascript,Json,Jsp,Servlets,以下是我用jsp编写的一段代码: 完整日历 <script src="js/jquery-1.9.1.js"></script> <script src="js/jquery-ui-1.8.13.custom.min.js"></script> <script type='text/javascript' src='fullcalendar/fullcalendar.js'></script> </head>
<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-ui-1.8.13.custom.min.js"></script>
<script type='text/javascript' src='fullcalendar/fullcalendar.js'></script>
</head>
<body>
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
theme: true,
editable: false,
events: "/SampleWeb/CalendarJsonServlet"
});
});
</script>
<div id="calendar"></div>
</body>
</html>
我已经按照示例代码中的指定创建了它,但当我修改它以从数据库中动态获取时,它就不起作用了。就像它从数据库中拾取数据直到servlet,但是当它必须在指定的日期显示时,没有错误,只有在特定位置显示空框。我工作的示例链接代码是:如果代码的javascript通信部分从服务器读取了正确的值,您是否尝试调试该部分代码,或者没有尝试搜索OnSuces事件。这样您就可以知道服务器实际发送的是什么。是的,Jigar Joshi,它只读取正确的数据。但不在特定日期显示。Suresh,您能给出示例代码如何使用onSuccess事件以及在何处?您能给出从servlet获得的json数据吗。我曾经遇到过这个插件的同样问题,特别是startDate和endDate格式的数据。仔细检查这两个字段。
<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-ui-1.8.13.custom.min.js"></script>
<script type='text/javascript' src='fullcalendar/fullcalendar.js'></script>
</head>
<body>
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
theme: true,
editable: false,
events: "/SampleWeb/CalendarJsonServlet"
});
});
</script>
<div id="calendar"></div>
</body>
</html>
public static ArrayList<HashMap<String, String>> calValues(String month, String year) {
HashMap<String, String> hm;
ArrayList<HashMap<String, String>> calrecord=new ArrayList<HashMap<String, String>>();
userBean user=new userBean();
System.out.println("inside JDBC "+month);
System.out.println(year);
String query="select * from caldata WHERE calmonth ="+month+"AND calyear ="+year;
try{
currentCon = ConnectionManager.getConnection();
stmt=currentCon.createStatement();
rs = stmt.executeQuery(query);
boolean more = rs.next();
// if month and year not exist
if (!more) {
System.out.println("Sorry, not valid");
}
//if month and year exists
else if (more) {
do{
hm=new HashMap<String,String>();
String repName=rs.getString("repname");
System.out.println("Report Name : "+repName);
String repFreq=rs.getString("repfrequ");
System.out.println("Report Frequency : "+repFreq);
String reportDate=rs.getString("repdate");
System.out.println("Report Date : "+reportDate);
hm.put("0", rs.getString("repname"));
hm.put("1", rs.getString("repfrequ"));
hm.put("2", rs.getString("repdate"));
calrecord.add(hm);
}while(rs.next());
}
}catch(Exception e){
System.out.println(e.getMessage());
}
return calrecord;
}
package com.model;
public class CalendarDTO {
public int id;
public String title;
public String start;
public String end;
public String color;
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getStart() {
return start;
}
public void setStart(String start) {
this.start = start;
}
public String getEnd() {
return end;
}
public void setEnd(String end) {
this.end = end;
}
}