简体   繁体   English

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

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

So i have been trying to make a blog engine. 因此,我一直在尝试制作博客引擎。 I want to insert a com.google.appengine.api.datastore.Text variable into the database. 我想将com.google.appengine.api.datastore.Text变量插入数据库。

I made a servlet and tried to accept a Text variable is a request.getParameter() 我做了一个servlet并尝试接受Text变量是request.getParameter()

The problem is that is gives me an error ~ 问题是给我一个错误〜

Type mismatch: cannot convert from String to Text 类型不匹配:无法从字符串转换为文本

This is my code: 这是我的代码:

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) {

    }
}

So how do i insert a Text variable into the database? 那么如何将Text变量插入数据库? If not by servlets.. is there another method? 如果不是通过servlet ..还有另一种方法吗?

Answers in java will be appreciated. Java的答案将不胜感激。

The constructor for the Text object takes in a String . Text对象的构造函数采用String So you should be able to write: 因此,您应该能够编写:

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.

相关问题 如何使用com.google.appengine.api.datastore.Text - how to use com.google.appengine.api.datastore.Text 使用com.google.appengine.api.datastore.Text时如何维护格式和缩进 - How to maintain formatting and indentation when using com.google.appengine.api.datastore.Text 如何将Google App Engine数据存储区中的数据写入com.google.appengine.api.datastore.Text - How do I write data in my Google App Engine Datastore to com.google.appengine.api.datastore.Text 引起:java.lang.ClassCastException:com.google.appengine.api.datastore.Text 无法转换为 java.lang.String - Caused by: java.lang.ClassCastException: com.google.appengine.api.datastore.Text cannot be cast to java.lang.String AppEngine ClassNotFoundException:com.google.appengine.api.datastore.DatastoreServiceFactory - AppEngine ClassNotFoundException: com.google.appengine.api.datastore.DatastoreServiceFactory 如何在Google App Engine _ah / api / explorer中创建com.google.appengine.api.datastore.Key对象? - How to create the com.google.appengine.api.datastore.Key object in the Google App Engine _ah/api/explorer? 将属性设置为com.google.appengine.api.datastore.Entity - Setting a property to com.google.appengine.api.datastore.Entity com.google.appengine.api.datastore.DatastoreNeedIndexException:找不到匹配的索引 - com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found com.google.appengine.api.datastore.DatastoreFailureException:意外失败 - com.google.appengine.api.datastore.DatastoreFailureException: Unexpected failure 示例应用中的com.google.appengine.api.datastore.DatastoreNeedIndexException错误 - com.google.appengine.api.datastore.DatastoreNeedIndexException error in Sample App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM