[英]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.