Desidero creare un codice codificato URL per il mio sito. Ad esempio, per questo URL: "http://google.com/index.html"Come URL codificare un URL in JSP?
Desidero fornire questo URL al client tramite l'URL che lo codifica.
Desidero creare un codice codificato URL per il mio sito. Ad esempio, per questo URL: "http://google.com/index.html"Come URL codificare un URL in JSP?
Desidero fornire questo URL al client tramite l'URL che lo codifica.
Dal momento che si sta utilizzando JSP, mi sarebbe attenersi a JSTL e not use scriptlets. È possibile utilizzare il tag JSTL <c:url />
in combination with <c:param />
:
<c:url value="/yourClient" var="url">
<c:param name="yourParamName" value="http://google.com/index.html" />
</c:url>
<a href="${url}">Link to your client</a>
Questo si tradurrà in:
<a href="/yourClient?yourParamName=http%3a%2f%2fgoogle.com%2findex.html">Link to your client</a>
Come posso passare un valore param vuoto? Ho provato '
Il valore vuoto funziona per me. –
Prova nel codice JSP:
Base64.encodeBase64("http://google.com/index.html")
Codifica Base64! = Codifica URL –
Utilizzando UrlEncoder.encode() è la risposta. Ma il punto è che questo metodo non codifica in percentuale. Utilizzare:
java.net.UrlEncoder.encode(stringOfURL,"UTF-8").replace("+","%20")
Perché si desidera eseguire questo su un JSP? Non puoi semplicemente usare [UrlEncoder.encode()] (http://docs.oracle.com/javase/1.5.0/docs/api/java/net/URLEncoder.html) sul servlet e passare i dati a il JSP? –