-1

I have an application with + sign in its name (eg. DB+JSP.jws).

I get an error when trying to create connection as java encodes url + with spaces and hence cannot add the connection to DB JSP/../META-INF/connection.xml (File not found exception).

Any way to circumvent this only by using URLEncoder.encode() and URLDecoder.decode() methods?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Ravi
  • 133
  • 10
  • see this it may helpful http://stackoverflow.com/questions/724043/http-url-address-encoding-in-java – Zaz Gmy May 04 '12 at 09:55

1 Answers1

0

You need to encode the URL correctly since '+' is a reserved character in a URL and can only be used in the correct context otherwise needs to be encoded with %2B.

Your URL string would encoded as "DB%2BJSP.jws".

So if you defined the following:

String url = URLEncoder.encode("DB+JSP.jws");
System.out.println(url);

The output would be the same:

DB%2BJSP.jws

You can prepend "http://localhost/" to the encoded URL as you need to.

CodeMonkey
  • 22,825
  • 4
  • 35
  • 75