How to stop URI from being encoding the reserved characters when executing? - java

I'm Trying to do an android app which contains an URI of a JSON file . The JSON File URI contains some reserved characters in the link and hence when executing, the link is being automatically replaced with the encoded form of those characters. therefore Im not being able to retrieve the JSON file from the link.
The link when entered in Browser shows output but through program it does not show.The link after encoding when entered in a browser show nothing but a blank page.
Sorry I Cant post the Link here...( Characters which are shown in the URI are {?,_ etc..} present in the link of the file.
How shall I COUNTER this problem?
(How to use the Escape characters to resolve this problem?)

Related

Unable to retrieve special characters like ® while using HttpServletResponseWrapper

I am unable to retrieve a special character (®) while using HttpServletResponseWrapper, processing the response with RequestDispatcher include.
I tried setting the character encoding to UTF-8 and also did try the configuration changes in WEB.xml. Still I am not able to retrieve the character and moreover, I am not even seeing an encoded string in place of the character.
Any help is appreciated.

How to do new line in messages_en.properties file in keycloak

I am modifying keycloak messages_en.properties file for the error message in regexpattern mismatch:
invalidPasswordRegexPatternMessage=Password must contain at least one special character\n
Password must contain at least one upper case character\n
Password must contain at least one numerical character\n
Password should not contain blank space\n
Password should consist of 8-15 characters
But it wont display a newline using \n in the toast that pop-up in the UI.
I tried backslash only but it also wont work.
You can directly use <br> in the message, but you must append ?no_esc to the message output in the freemarker .ftl file.
Examples:
${msg("msgId")?no_esc}
${kcSanitize(message.summary)?no_esc}
I used br tag and then in html i added: ng-bind-html="notification.message"
And in the services.js file i found the notifications.error there so i added 'ngSanitize' as a dependency based on this guide: https://www.w3schools.com/angular/ng_ng-bind-html.asp

MySQL - Java - Can't handle special characters

I have a JTextArea from which I get the text, and send it through a POST request to a PHP page, which uses PDO and a prepare statement to insert the text into a MySQL database. This works for everything that I can type directly into the JTextArea. However, it doesn't work when I copy and paste something from Word, for example, into the JTextArea and then upload it.
For example, if I type into Word: "This is a super—long dash." Then copy and paste that in the JTextArea and have it send to the PHP page, which will upload it to the MySQL server, when I get the information back from the MySQL server (using another PHP page) it comes back as "This is a super—long dash."
This also happens for other various special characters, not just long dashes.
Is there anything I can do about this?
EDIT:
I tried to correct the issue by making sure all my php files are using utf8 to connect to mysql like so:
"mysql:host=$servername;dbname=$dbname;charset=utf8"
I also use
echo $_POST[xxx];
To make sure the text is coming in from java correctly, which it is. When I check what is the mysql database, it shows as "This is a superùlong dash". I tried to correct this by using the fixUTF8 function in the solution here: Detect encoding and make everything UTF-8 by Sebastián Grignoli. However, as a result I get "This is a super?long dash".

What could be wrong with my file download method?

I have an app which allows users to upload a file. User is sent to a preview page where they can download the file they just uploaded to sorta verify that things are correct. But for some reason the filename is not correct when it reaches the servlet, what could cause this?
$('a[id^=dl_link_]').click(function(e) {
e.preventDefault();
$('#dl_form input[name=file_name]').val($(this).text());
$('#dl_form input[name=uid]').val(upload.tempId);
$('#dl_form').submit();
});
When I add logs, I see that the file name is correct; ie "this is a test file.docx".
But when this data gets to the backend I get the following:
java.io.FileNotFoundException: /Users/yao/__TEMP__/upload_temp/1111/0gGNMY8PcAWEs3M/this�is�a�test�file.docx (No such file or directory)
The file path is constructed by combining parts together. The servlet receives the uid and the filename, everything else is from some other backend methods.
What could be the cause of this?
Maybe you need to call
encodeURIComponent()
on the file name. It'll convert the space chars to %20 and then be converted properly on the back end.
As I see the problem is related with the space character. This question might help you: accessing files with spaces in filename from java

response.sendredirect with url with foreign chars - how to encode?

I have a jsf app that has international users so form inputs can have non-western strings like kanjii and chinese - if I hit my url with ..?q=東日本大 the output on the page is correct and I see the q input in my form gets populated fine. But if I enter that same string into my form and submit, my app does a redirect back to itself after constructing the url with the populated parameters in the url (seems redundant but this is due to 3rd party integration) but the redirect is not encoding the string properly. I have
url = new String(url.getBytes("ISO-8859-1"), "UTF-8");
response.sendRedirect(url);
But url redirect ends up being q=???? I've played around with various encoding strings (switched around ISO and UTF-8 and just got a bunch of gibberish in the url) in the String constructor but none seem to work to where I get q=東日本大 Any ideas as to what I need to do to get the q=東日本大 populated in the redirect properly? Thanks.
How are you making your url? URIs can't directly have non-ASCII characters in; they have to be turned into bytes (using a particular encoding) and then %-encoded.
URLEncoder.encode should be given an encoding argument, to ensure this is the right encoding. Otherwise you get the default encoding, which is probably wrong and always to be avoided.
String q= "\u6771\u65e5\u672c\u5927"; // 東日本大
String url= "http://example.com/query?q="+URLEncoder.encode(q, "utf-8");
// http://example.com/query?q=%E6%9D%B1%E6%97%A5%E6%9C%AC%E5%A4%A7
response.sendRedirect(url);
This URI will display as the IRI ‘http://example.com/query?q=東日本大’ in the browser address bar.
Make sure you're serving your pages as UTF-8 (using Content-Type header/meta) and interpreting query string input as UTF-8 (server-specific; see this faq for Tomcat.)
Try
response.setContentType("text/html; charset=UTF-16");
response.setCharacterEncoding("utf-16");

Categories