我正在开发一个导出日历的应用程序。我遇到的问题是日历是下载的,而不是用 Outlook 打开的。这是我的代码:
1) 主页面有图片链接导出日历:
<img src="/calendar.png" width="32" Style="width: 32px; height:32px;" title="Calendar" onClick="javascript:document.getElementById('exportCal').submit();">
<form id="exportCal" action="Calendar.jsp" target="_blank" method="post">
<INPUT TYPE="hidden" ID="calendarData" NAME="calendarData" VALUE=""/>
</form>
2)在链接重定向到的jsp中,我生成.ics(使用iCal4j库)文件并将其附加到响应中:
response.setHeader ("Content-Disposition", "inline;filename=\"mycalendar.ics\"");
response.setContentType("text/calendar");
Calendar calendar = new Calendar();
calendar.getProperties().add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN"));
calendar.getProperties().add(Version.VERSION_2_0);
calendar.getProperties().add(CalScale.GREGORIAN);
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.set(java.util.Calendar.MONTH, java.util.Calendar.DECEMBER);
cal.set(java.util.Calendar.DAY_OF_MONTH, 25);
// initialise as an all-day event..
VEvent christmas = new VEvent(new Date(cal.getTime()), "Christmas Day");
// Generate a UID for the event..
UidGenerator ug = new UidGenerator("1");
christmas.getProperties().add(ug.generateUid());
calendar.getComponents().add(christmas);
System.out.println(calendar);
ServletOutputStream fout = response.getOutputStream();
CalendarOutputter outputter = new CalendarOutputter();
outputter.output(calendar, fout);
fout.flush();
然后,.ics 被下载。但我真正想做的是用 Outlook 打开它。有没有办法做到这一点?
提前致谢!!