0
votes
 package com.example.datastoreWrite;

 import java.io.IOException;

 import javax.servlet.ServletException;

 import javax.servlet.http.HttpServlet;

 import javax.servlet.http.HttpServletRequest;

 import javax.servlet.http.HttpServletResponse;

 @SuppressWarnings("serial")

 public class DataStoreWriteServlet extends HttpServlet
 {

 @Override

 protected void doGet(HttpServletRequest req, HttpServletResponse resp)

 throws ServletException, IOException {

 // TODO Auto-generated method stub

 Key v1 = KeyFactory.createKey("Person", "Raghav");

 Key r1 = KeyFactory.createKey("Person", "vinay");

 DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

 Entity e1, e2;

 try {

 e1 = datastore.get(r1);

 e2 = datastore.get(v1);

 Long vAge = (Long) e1.getProperty("age");

 Long rAge = (Long) e2.getProperty("age");

 System.out.println("vinay age"+vAge);

 System.out.println(" age"+rAge);

 } catch (EntityNotFoundException e) {

 // Alice or Bob doesn't exist!
 }
 String message = "Simple";

 req.setAttribute("message", message); // This will be available as ${message}

 try {

 req.getRequestDispatcher("/Show.jsp").forward(req, resp);

 } catch (ServletException e) {

 // TODO Auto-generated catch block

 e.printStackTrace();
 }}}

HERE is MY JSP FILE

 <%@ page language="java"

 <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

 <title>Simple DataStore Display</title></head>

 <body><p>Message: ${message}</p></body>

 </html>

MY WEB.xml

xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

<servlet>
<servlet-name>SimpleDataStoreApplicationTest</servlet-name>
<servlet-class>com.datasote.test.SimpleDataStoreApplicationTestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleDataStoreApplicationTest</servlet-name>
<url-pattern>/simpledatastoreapplicationtest</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list></web-app>
1

1 Answers

0
votes

I suspect you have forgotten to close the page directive properly in the Show.jsp file.

Please use : <%@ page language="java"%>.

Other than the above, your code looks good to execute and if the data is not present, you will see the Message: Simple output in the Show.jsp page.