简体   繁体   中英

How to create an “add to calendar” iCal link (.ics file) from server data and send it back to my webApp?

I am working on prototyping something, and I'm hoping someone can help me. I am trying to create an Add event to calendar link which will download and open an iCal file (.ics), so that they can add it to their calendar.

We are using Jax-RS with Jersey and tomcat as the container, and I have the iCal4j package. The client is jQuery/backbone.

  1. I am not sure which is the correct way to return the data. If I should be creating an ics file and storing it somewhere before returning it, or sending back a CalendarOutputter filestream from iCal4j?
  2. If I do create an ics file, where do I store that? WEB-INF folder? How?
  3. If returning the filestream, what is the correct @Produces(?) for Jax-RX?

Thanks, Ray

You should not create a file to return the data. You should be able to return your Calendar object directly. Try something like:

@GET
@Path("calendar")
@Produces("text/calendar")
public Response generateCalendar() {
  Calendar calendar = new Calendar();
  // Generate your calendar here
  ResponseBuilder builder = Response.ok();
  builder.header("content-disposition", "attachment;filename=calendar.ics");
  builder.entity(calendar.toString());
  return builder.build();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM