📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (176K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
URL Decoder Online
URL Decoder is an online tool for decoding URLs. Note that, our tool assumes that the input is encoded using the UTF-8 encoding scheme. The worldwide web consortium recommends using the UTF-8 encoding scheme when working with URLs.Check out URL Encoder Online tool at URL Encoder Online
URL Decode Example
Decoded URL input:
https%3A%2F%2Fwww.javaguides.net%2Fp%2Furl-decoder-online.htmlEncoded URL output:
https://www.javaguides.net/p/url-decoder-online.html
What is URL Decoding and why is it required?
URL decoding is the inverse process of URL encoding. It is used to parse query strings or path parameters passed in URLs. It is also used to decode HTML form parameters that are submitted with application/x-www-form-urlencoded MIME format
URLs, as you might know, can only contain a limited set of characters from the US-ASCII character set. These characters include Alphabets (A-Z a-z), Digits (0-9), hyphen (-), underscore (_), tilde (~), and dot (.). Any character outside this allowed set is encoded using URL encoding or Percent encoding.
This is why it becomes necessary to decode query strings or path parameters passed in URLs to get the actual values.
Decode URL in JavaScript
Let's first encode using the decodeURIComponent() method and then decode it using the encodeURIComponent() function.
var uri = "https://javaguides.net/my test.html?name=ram&age29"; console.log("before encode :: " + uri); var encode = encodeURIComponent(uri); console.log("after encode :: " + encode); var decode = decodeURIComponent(encode); console.log("after decode :: " + decode);
Output:
before encode :: https://javaguides.net/my test.html?name=ram&age29 after encode :: https%3A%2F%2Fjavaguides.net%2Fmy%20test.html%3Fname%3Dram%26age29 after decode :: https://javaguides.net/my test.html?name=ram&age29
Read more about how to encode and decode URL in JavaScript in a blog post at Encode and Decode URL in JavaScript.
URL Decode in Java
In Java, URLDecoder class provides a decode() method which decodes an application/x-www-form-urlencoded string using a specific encoding scheme.
The below program demonstrates the usage of the decode() method:
package net.javaguides.network; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLDecoder; import java.net.URLEncoder; public class URLDecoderExample { public static void main(String[] args) throws UnsupportedEncodingException, MalformedURLException { // base URL String baseurl = "https://www.javaguides.net/search?q="; // String to be encoded String query = "core+java+tutorial"; System.out.println("URL without encoding :"); URL url = new URL(baseurl + query); System.out.println(url); // encode() method System.out.println("URL after encoding :"); String encodedStr = URLEncoder.encode(query, "UTF-8"); url = new URL(baseurl + encodedStr); System.out.println(url); // decode url process System.out.println("Encoded URL :"); System.out.println(baseurl + encodedStr); // decode() method System.out.println("Decoded URL :"); String decode = URLDecoder.decode(encodedStr, "UTF-8"); System.out.println(baseurl + decode); } }
Output:
URL without encoding : https://www.javaguides.net/search?q=core+java+tutorial URL after encoding : https://www.javaguides.net/search?q=core%2Bjava%2Btutorial Encoded URL : https://www.javaguides.net/search?q=core%2Bjava%2Btutorial Decoded URL : https://www.javaguides.net/search?q=core+java+tutorial
Our example uses UTF-8 encoding for decoding the URLs. You should always use UTF-8 to avoid incompatibilities with other systems. That is what the world wide web consortium recommends.
Check out how to encode and decode URLs in Java at Java URLEncoder and URLDecoder Class Examples
Comments
Post a Comment
Leave Comment