Encoding as Base64 in Java

I need to encode some data in the Base64 encoding in Java. How do I do that? What is the name of the class that provides a Base64 encoder? I tried to use the sun.misc.BASE64Encoder class, without success. I have the following line of Java 7 code: wr.write(new sun.misc.BASE64Encoder().encode(buf)); I’m using Eclipse. Eclipse marks this … Read more

Encode URL in JavaScript?

How do you safely encode a URL using JavaScript such that it can be put into a GET string? var myUrl = “http://example.com/index.html?param=1&anotherParam=2”; var myOtherUrl = “http://example.com/index.html?url=” + myUrl; I assume that you need to encode the myUrl variable on that second line? 2 21 Check out the built-in function encodeURIComponent(str) and encodeURI(str). In your … Read more