SóProvas


ID
2543230
Banca
FGV
Órgão
SEPOG - RO
Ano
2017
Provas
Disciplina
Programação
Assuntos

Considere a querystring apresentada a seguir criada em um servlet Java:


estado=Rond%C3%B4nia&capital=Porto+Velho


Assinale a opção que contém o código Java que codifica a querystring para esse formato.

Alternativas
Comentários
  • Gabarito C

  • ESSA É DE FUDE!#@!@#!@#!@3

  • Para que serve a classe URLEncoder?

    • Utility class for HTML form encoding;
    • Contains static methods for converting a String to the  MIME format.

    Ao converter uma String, quais regras serão aplicadas?

    • The alphanumeric characters "a" through "z", "A" through "Z" and "0" through "9" remain the same;
    • The special characters ".", "-", "*", and "_" remain the same;
    • The space character " " is converted into a plus sign "".; // Por isso que temos Porto+Velho
    • All other characters are unsafe and are first converted into one or more bytes using some encoding scheme. Then each byte is represented by the 3-character string "%xy", where xy is the two-digit hexadecimal representation of the byte. The recommended encoding scheme to use is UTF-8. However, for compatibility reasons, if an encoding is not specified, then the default encoding of the platform is used. // Por isso temos %C3%B4 na palavra Rondônia

    URLEncoder possui o método encode, que:

    • Translates a string into  format using a specific encoding scheme;
    • This method uses the supplied encoding scheme to obtain the bytes for unsafe characters. // No caso, foi utilizado o UTF-8

    O método encode tem dois parâmetro:

    1. O primeiro será a String a ser convertida;
    2. O nome do codificador (encoding) que utilizaremos.

    Voltando para a questão, podemos marcar a alternativa "C":

    String querystring = "estado=" +

    URLEncoder.encode("Rondônia", "UTF-8") + "&capital=" +

    URLEncoder.encode("Porto Velho", "UTF-8");

    Fonte: https://docs.oracle.com/javase/7/docs/api/java/net/URLEncoder.html