0

when i pass string with space in bw the words to the servlet and run the android aaplication error comes like this

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

but it works fine when i pass single word string like ads_title=test and city = Delhi

but when i run query on sql with both the value that works that means query is fine.

String stringURL="http//laddress of server:8088/First/MyServlet" +
String.format("?ads_title=%s&city=%s",editText1.getText(),City); 

that is where i am passing the values

tinos07
  • 105
  • 1
  • 11

2 Answers2

2

Data sent as a URL must be "encoded" to ensure that all the data passes properly to the server to be interpreted correctly. Fortunately, Java provides a standard class URLEncoder and the encoding specified by the World Wide Web Consortium is "UTF-8 so, use

String finalURL = URLEncoder(stringURL,"UTF-8");

(That way you don't have to know what the encoding is for each special character.)

ErstwhileIII
  • 4,829
  • 2
  • 23
  • 37
1

I agree with the comments (not sure why they didn't post as an answer though?) - you want to try encoding your URL - so that the space is handled correctly (%20)

Java URL encoding of query string parameters

Community
  • 1
  • 1
monojohnny
  • 5,894
  • 16
  • 59
  • 83