自定义搜索
上一篇:下载Eclipse的链接
下一篇:加拿大买卖房的几个网站,备份一下,买房时可能用的上;
一个简单的使用Google DataStore的例子
米娅 2012年1月31日 14:02:42

java 文件 

import java.util.Date;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.EntityNotFoundException;
import java.io.IOException;

 
public class DataStore {

    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Date putDate = new Date();
    Entity entity = null;
    String links = "";

    public String createEntity(String headlines, String entity_key) {

        entity = new Entity(headlines, entity_key);

        entity.setProperty("Name", null);
        entity.setProperty("Link", null);
        entity.setProperty("Date", putDate);
        entity.setProperty("Description", null);
        datastore.put(entity);

        return "create";
    }

    public String updateEntity(Key entity_key, String name, String link, String description) {

        try {
            entity = datastore.get(entity_key);

            entity.setProperty("Name", name);
            entity.setProperty("Link", link);
            entity.setProperty("Date", putDate);
            entity.setProperty("Description", description);

            datastore.put(entity);

        } catch (EntityNotFoundException e) {
        }

        return "update";
    }

    public String deleteEntity(Key entity_key) {

        datastore.delete(entity_key);
        return "delete";
    }

    public String getPropertiesOfEntity(Key entity_key) {

        try {

            entity = datastore.get(entity_key);
            String media_name = (String) entity.getProperty("Name");
            String news_links = (String) entity.getProperty("Link");

            links = media_name + news_links;

        } catch (EntityNotFoundException e) {
        }

        return "get" + links;
    }

    public String getLinks() {

        String key_str = "H";

        Key entity_key = KeyFactory.createKey("Headlines", key_str);

        //       createEntity("Headlines", key_str);
        //       updateEntity(entity_key, "1", "2", "3");
        //     deleteEntity(entity_key);

        return "Well done" + getPropertiesOfEntity(entity_key);
    }
}

 

jsp文件:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="DataStore" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello World!</h1>

        <%

            DataStore Database = new DataStore();


        %>

        <%= Database.getLinks() %>
 
    </body>
</html>


共1页
相关链接
1. How to make a website look like this on google.com?
2. Google企业邮箱管理面板登录网址链接
3. 更改DNS后,无法用网址mail.domainname.com访问Google企业邮箱(已解决)
4. 改过DNS后,Google企业邮箱不能收邮件(已解决)
5. Google API 列表 && Google merchant center
6. 在网站使用Google地图笔记
7. 优化Google Adsense:通过区段定位突出重要内容
8. Google如何匹配网页的Google Adsense广告
9. 如何提高网站的Google Adsense广告收入
10. Apple iphone市场份额被Google Android吃掉一口的宿命(图)
11. 用CSS制作阴影效果(兼容IE、Firefox、Google Chrome)
12. 网传Google面试题
13. 兼容IE、Firefox、Google Chrome的DIV透明处理
14. Google Analytics如何收费
15. 提高Google AdSense广告点击率
16. Google产品列表,Google是越来越神奇了