简体   繁体   中英

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.

I made a servlet and tried to accept a Text variable is a 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? If not by servlets.. is there another method?

Answers in java will be appreciated.

The constructor for the Text object takes in a 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) {
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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