Appengine数据存储区中的值不会显示

|
This is my first servlet...

public class ServletCheckServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        resp.setContentType(\"text/plain\");

    PrintWriter pw=resp.getWriter();
    String s1=req.getParameter(\"username\");
    String s2=req.getParameter(\"password\");

    DatastoreService datastore=DatastoreServiceFactory.getDatastoreService();
    Entity employee=new Entity(\"Employee\");

    employee.setProperty(\"firstname\", \"Ram\");
    employee.setProperty(\"lastname\", \"prasad\");


    Date hiredate=new Date();
    employee.setProperty(\"Hiredate\", hiredate);
    employee.setProperty(\"attendedHRtraining\",true);
    datastore.put(employee);

    Key employeekey=KeyFactory.createKey(\"employees\", \"employee1\");
}
}
我的第二个servlet在下面。
public class ValidUserServlet extends HttpServlet{
protected void doGet(HttpServletRequest req,HttpServletResponse resp){
    PrintWriter pw;
    try {
        pw = resp.getWriter();
        pw.println(\"Welcome to the second servlet\");

        Key employeekey=KeyFactory.createKey(\"employees\", \"employee1\");

    DatastoreService datastore=DatastoreServiceFactory.getDatastoreService();
        try {
            Entity employee=datastore.get(employeekey);
            String fn=(String) employee.getProperty(\"firstname\");

            pw.println(fn);


        } catch (EntityNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


}

}
但是,当我运行此应用程序时..... servlet出现了...但是未显示Appengine数据存储区中的值... 我的程序中有什么问题...如何清除...是否正确... 请帮我.......
已邀请:
而不是使用
Key employeekey=KeyFactory.createKey(\"employees\", \"employee1\");
您可以使用
Entity employeeEntity = datastore.get(KeyFactory.stringToKey(employee.getId()));
由于您使用的是旧的servlet,因此您可以从请求中获得
employeeId
String employeeId = request.getParameter(\"employeeId\");
Entity employeeEntity = datastore.get(KeyFactory.stringToKey(employeeId);
您可以参考此源代码以进一步阐明。

要回复问题请先登录注册