package guestbook;
import java.io.IOException;
import java.util.logging.Logger;
import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
@SuppressWarnings("serial")
public class RemoveGreetingServlet extends HttpServlet{
private static final Logger log = Logger.getLogger(RemoveGreetingServlet.class.getName());
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PersistenceManager pm = PMF.get().getPersistenceManager();
Key key = KeyFactory.stringToKey(req.getParameter("key"));
Greeting greeting = pm.getObjectById(Greeting.class, key) ;
log.info("Removing Greeting: " + greeting.getContent());
pm.deletePersistent(greeting);
resp.sendRedirect("/guestbook.jsp");
}
}