繁体   English   中英

如何在数据库中存储“ com.google.appengine.api.datastore.Text”

[英]How to store “com.google.appengine.api.datastore.Text” in database

因此,我一直在尝试制作博客引擎。 我想将com.google.appengine.api.datastore.Text变量插入数据库。

我做了一个servlet并尝试接受Text变量是request.getParameter()

问题是给我一个错误〜

类型不匹配:无法从字符串转换为文本

这是我的代码:

public void doGet(HttpServletRequest req, HttpServletResponse res){

    try {
        String action = req.getParameter(Constants.ACTION);

        if(action.equals("add")){
                //The next line gives the error
            Text description = req.getParameter("description"); 
        }

    } catch (Exception e) {

    }
}

那么如何将Text变量插入数据库? 如果不是通过servlet ..还有另一种方法吗?

Java的答案将不胜感激。

Text对象的构造函数采用String 因此,您应该能够编写:

public void doGet(HttpServletRequest req, HttpServletResponse res){
  try {
    String action = req.getParameter(Constants.ACTION);
    if(action.equals("add")){
      Text description = new Text(req.getParameter("description")); 
    }
  } catch (Exception e) {
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM