[OmniFaces utilities] The
encodeURI()
method encodes the given string using UTF-8. URIs (paths and filenames) have different encoding rules as compared to URLs. URLEncoder
is actually only for www (HTML) form based query string parameter values. URI encoding has a lot in common with URL encoding, but the space has to be %20
and some chars doesn't necessarily need to be encoded.Method
Usage
import
org.omnifaces.util.Utils;
...
// http%3A%2F%2Fwww.names.org%3Fname%3DAnghel%20Leonard
String encode_uri =
Utils.encodeURI("http://www.names.org?name=Anghel Leonard");
// check
#encodeURL() also
// http%3A%2F%2Fwww.names.org%3Fname%3DAnghel+Leonard
String
encode_url = Utils.encodeURL("http://www.names.org?name=Anghel
Leonard");
Notice
how the empty space was encoded by #encodeURI() as %20, while #encodeURL() as +.
Niciun comentariu :
Trimiteți un comentariu