package ch.hes_so.mse.cloud;

import java.io.IOException;
import javax.servlet.http.*;

@SuppressWarnings("serial")
public class DatastoreWriteServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		resp.setContentType("text/plain");
		resp.getWriter().println("Hello, world from Datastore");
	}
}

@@ -66,24 +66,261 @@
 java
-x.servlet.http.*
+.io.PrintWriter;%0Aimport java.util.Enumeration;%0A%0Aimport javax.servlet.http.*;%0A%0Aimport com.google.appengine.api.datastore.DatastoreService;%0Aimport com.google.appengine.api.datastore.DatastoreServiceFactory;%0Aimport com.google.appengine.api.datastore.Entity
 ;%0A%0A@
@@ -493,16 +493,47 @@
 ption %7B%0A
+%09%09%0A%09%09// Define the output type%0A
 %09%09resp.s
@@ -567,61 +567,1102 @@
 ;%0A%09%09
-resp.getWriter().println(%22Hello, world from Datastore
+%0A%09%09PrintWriter pw = resp.getWriter();%0A%09%09%0A%09%09if(!req.getParameterNames().hasMoreElements())%0A%09%09%7B%0A%09%09%09pw.println(%22ERROR: No argument specified for writing a new book entity.%22);%0A%09%09%09return;%0A%09%09%7D%0A%09%09%0A%09%09pw.println(%22Writing entity to datastore.%22);%0A%09%09%0A%09%09// Gets the entity name, this is mandatory argument.%0A%09%09String entityName = req.getParameter(%22entityName%22);%0A%09%09%0A%09%09// Retrieve the store service from Google.%0A        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();%0A        %0A        // Create a new book entity%0A        Entity newEntity = new Entity(entityName);%0A        %0A%09%09// Gets the parameters of the page passed in the URL%0A        Enumeration%3CString%3E paramerterNames = req.getParameterNames();%0A        while(paramerterNames.hasMoreElements())%0A        %7B%0A        %09String parameterName = paramerterNames.nextElement();%0A        %09String parameterValue = req.getParameter(parameterName);%0A        %09%0A        %09newEntity.setProperty(parameterName, parameterValue);%0A        %7D%0A        %0A        // Save the entity%0A        datastore.put(newEntity);%0A        %0A        pw.println(%22Entity saved.
 %22);%0A

Update servlet for writing many entities and its properties.