1. 程式人生 > >使用URLEncoder、URLDecoder進行URL引數的轉碼與解碼

使用URLEncoder、URLDecoder進行URL引數的轉碼與解碼

url後引數的轉碼與解碼

import java.net.URLDecoder;
import java.net.URLEncoder;

  String strTest = "?=abc?中%1&2<3,4>";
  strTest = URLEncoder.encode(strTest, "UTF-8");
  System.out.println(strTest);
  strTest = URLDecoder.decode(strTest,"UTF-8");
  System.out.println(strTest);

執行結果:

%3F%3Dabc%3F%E4%B8%AD%251%262%3C3%2C4%3E
?=abc?中%1&2<3,4>

jdk相關說明:

Translates a string into application/x-www-form-urlencoded format using a specific encoding scheme. This method uses the supplied encoding scheme to obtain the bytes for unsafe characters.

Note: The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing so may introduce incompatibilites.

Decodes a application/x-www-form-urlencoded string using a specific encoding scheme. The supplied encoding is used to determine what characters are represented by any consecutive sequences of the form "%xy".

Note: The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing so may introduce incompatibilites.

Parameters:
s the String to decode
Returns:
the newly decoded String
Throws:
UnsupportedEncodingException - If character encoding needs to be consulted, but named character encoding is not supported
Since:
1.4
See Also:

相關推薦

使用URLEncoderURLDecoder進行URL引數解碼

url後引數的轉碼與解碼 import java.net.URLDecoder;import java.net.URLEncoder;   String strTest = "?=abc?中%1&2<3,4>";  strTest = URLEnco

使用URLEncoderURLDecoder進行URL參數的解碼

import encoder coder 鍵值對 str enc abc 地址 imp url參數的轉碼與解碼 import java.net.URLDecoder; import java.net.URLEncoder; String strTest =

c++ 實現url解碼 urlencode urldecode

 在網上找的程式碼各種問題,最終根據網上的版本修改實現了自己的一個版本,其中= 不做處理,- _都進行了轉碼 [cpp] view plain copy print? #include<iostream>#include<stdio.h&

c++ 實現url解碼 urlencode urldecode

在網上找的程式碼各種問題,最終根據網上的版本修改實現了自己的一個版本,其中= 不做處理,- _都進行了轉碼 #include<iostream> #include<stdio.h> using namespace std; static unsi

url中傳遞中文引數時的解碼

1、傳遞引數時需要使用encodeURIComponent,這樣組合的url才不會被#等特殊字元截斷。                             例如:<script language="javascript">document.write('<a href="http://

tp5中,模板控制器js的url方法

false header type 控制 lang dex RM ext TP $this->redirect(‘/Supperman/outerMan‘);$this->display(‘Supperman:outerMan‘);這兩者都只是在當前頁面打開新的

URLEncoderURLDecoder

block cep ner url coder ace div 解碼 ring public static void main(String[] args) { String a = "歡迎你"; try { //編碼 String b = URLEn

javascript使用btoa和atob來進行Base64解碼

ring scrip str pre AS sid encode highlight nbsp javascript中如何使用Base64轉碼 let str = ‘javascript‘; let btoaStr = window.btoa(str); //轉碼

URL中中文解碼

在爬取資料是時候很多搜尋的詞語中在瀏覽器上顯示的是中文,但是我們複製url到本地,中文就會出現我們看不懂的文字。 如果我們需要爬蟲的時候也是一樣,我們需要給瀏覽器傳過去的也是對url中的中文進行轉碼之後的url地址,否則在url中的關鍵字直接出現中文會有問題。在python3的環境中的url

【ARM-Linux開發】【CUDA開發】【視訊開發】關於Linux下利用GPU對視訊進行硬體加速的方案

最近一直在研究Linux下利用GPU進行硬體加速轉碼的方案,折騰了很久,至今沒有找到比較理想的硬加速轉碼方案。似乎網上討論這一方案的文章也特別少,這個過程中也進行了各種嘗試,遇到很多具體問題,以下便對之前所作的一些工作做一些總結和分享,省的時間長了自己也忘記了,也希望後來

使用jave1.0.2.jar進行音視訊

直接上程式碼: package com.roots.cloudserver.util; import it.sauronsoftware.jave.AudioAttributes; import it.sauronsoftware.jave.Encoder; import

javascript 使用btoa和atob來進行Base64解碼

javascript原生的api本來就支援,Base64,但是由於之前的javascript侷限性,導致Base64基本中看不中用。當前html5標準正式化之際,Base64將有較大的轉型空間,對於Html5 Api中出現的如FileReader Api, 拖拽上傳,甚至

java中url中文問題

public static void main(String[] args){ try { System.out.println("中文");//1 System.out.println("中文".getBytes(

js中post中文參數解碼

OS AR 轉碼 encode encodeuri 前端 部分 進行 code 作為基礎知識和血淋林的教訓,前端一定要記得post請求時將參數中帶有中文的部分進行轉碼!! var str=‘宋宇·特弱夫斯基‘; //轉碼: encodeURI(encodeURI(str))

HTML的Encode()和解碼(Decode)

HTML的Encode(轉碼)和解碼(Decode)在平時的開發中也是經常要處理的,在這裡總結了使用javascript處理HTML的Encode(轉碼)和解碼(Decode)的常用方式 一、用瀏覽器內部轉換器實現轉換 1.1.用瀏覽器內部轉換器實現html轉碼   首先動態建立一個容器

JAVAWEB圖片存入資料庫的圖片的譯碼

package foreiger.utils; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.i

使用encodeURI和decodeURI解碼

encodeURI() 函式可把字串作為 URI 進行編碼。 語法: encodeURI(URIstring) 引數 描述 URIstring 必需。一個字串,含有 URI 或其他要編碼的文字。 返回: URIstri

微信小程式不支援window物件及Navigator物件Base64解碼問題

本程式碼來源網址:http://www.xuebuyuan.com/zh-hant/1810251.htmlvar base64hash = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';// btoa method//b

Java如何進行Base64的編碼(Encode)解碼(Decode)?

*********************************************************** 關於base64編碼Encode和Decode編碼的幾種方式 Base64是一種能將任意Binary資料用64種字元組合成字串的方法,而這個Bina

Java進行Base64的編碼(Encode)解碼(Decode)

關於base64編碼Encode和Decode編碼的幾種方式 Base64是一種能將任意Binary資料用64種字元組合成字串的方法,而這個Binary資料和字串資料彼此之間是可以互相轉換的,十分方便。在實際應用上,Base64除了能將Binary資料視覺化之外,也常用來表示字串加密過後的內容。如果要使用J