这两天发现jQuery一个很好的日历插件--fullcalendar,于是就从网上搜集了一些资料,自己写了个小demo。
1、jsp也没代码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>fullcalendar test</title>
<link href='fullcalendar/fullcalendar.css' rel='stylesheet' />
<link href='fullcalendar/fullcalendar.print.css' rel='stylesheet' media='print' />
<script src='jquery/jquery-1.9.1.min.js'></script>
<script src='jquery/jquery-ui-1.10.2.custom.min.js'></script>
<script src='fullcalendar/fullcalendar.min.js'></script>
<style>
body {
margin-top: 40px;
text-align: center;
font-size: 14px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}
#calendar {
width: 900px;
margin: 0 auto;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
monthNamesShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
dayNames: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
dayNamesShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
today: ["今天"],
/* buttonText:{
prev: '上一页',
next: '下一页',
prevYear: '去年',
nextYear: '明年',
today: '今天',
month: '月',
week: '周',
day: '日'
}, */
editable: true,
currentTimezone: 'Asia/Beijing',
events:"servlet/GetJsonServelt"
});
})
</script>
</head>
<body>
<div id='calendar'></div>
</body>
</html>
2、Java代码(servlet中doPost的方法)
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
String returnValue ="[{\"id\":1,\"title\":\"Event1\",\"start\":\"2014-08-10\",\"url\":\"http:\\/\\/yahoo.com\\/\"},{\"id\":2,\"title\":\"Event2\",\"start\":\"2014-08-20\",\"end\":\"2014-08-22\",\"url\":\"http:\\/\\/yahoo.com\\/\"}]";
System.out.println(returnValue);
response.getWriter().print(returnValue);
out.flush();
out.close();
}