当我将 bw 中带有空格的字符串传递给 servlet 并运行 android 应用程序时 错误是这样的
03-01 09:32:41.110: E/Excepiton(1301): java.io.FileNotFoundException: http//address of server:8088/First/MyServlet?ads_title=test test&city=Pune
here ads_title=test
test and city = Delhi
但是当我传递单个单词字符串时它工作正常
像 ads_title=test
和 city = Delhi
但是当我在 sql 上运行查询时,这两个值都有效,这意味着查询很好。
String stringURL="http//laddress of server:8088/First/MyServlet" +
String.format("?ads_title=%s&city=%s",editText1.getText(),City);
那是我传递值的地方
最佳答案
作为 URL 发送的数据必须经过“编码”,以确保所有数据正确传递到服务器以得到正确解释。幸运的是,Java 提供了一个标准类 URLEncoder 并且万维网联盟指定的编码是“UTF-8 所以,使用
String finalURL = URLEncoder(stringURL,"UTF-8");
(这样你就不必知道每个特殊字符的编码是什么。)
关于java - 多个词不被搜索,不占用空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22114576/