I am sorry if this is answered somewhere else, but I've tried searching for similar problem to mine but can't find it.
I will try to keep it simple. I work with some nice legacy code and when a user clicks a Swing button, an URL with the chosen parameters (two names) is sent to ProcessBuilder()
that opens Internet Explorer. The URL contains both quotation marks (") and the names have Scandinavian characters. Problem is that those letters get turned into question marks which gives no match, so the user has to search for the same names again.
I have used URLEncoder()
for the names and the quotation marks (which have to be there for the site to get any result) to UTF-8. When I use the ProcessBuilder(ie_explorer, encodedString).start()
it still won't work. But, it does work for Chrome!
As I understand it, ProcessBuilder
sends the URL to the cmd. So in cmd, I wrote the path to each program (IE and Chrome) and sent the URL that works with Chrome. Obviously Chrome returns a result but IE doesn't, encoded or not.
I wrote chcp
in command prompt window and the result is 850.
Sadly making the users all use Chrome is not an acceptable solution. I have to make IE work. So I am turning to you guys in hopes of help.
What kind of encoding should I do to make cmd + IE happy with the URL?
Should I be opening the IE in a different way other than ProcessBuilder
?
I am super thankful for all help and answers!
PS: If it helps, the browser versions are Internet Explorer 11 and Google Chrome 55.0
Edit 1: Did as told and created a bat file that ran instead of IE/Chrome, and it is still the same long URL with encoded quotation marks and Scandinavian characters. So the output is simply "command + url" so like (I just included the ending of the URL for security reasons):
"X\X\X\Desktop\test.bat" "Action=Navigate&col1=%22D+Vy%22.%22Organisation%22&val1=%22LFC+S%C3%B6dert%C3%A4lje+%280181%29%22&col2=%22D+Vy%22.%22Vy%22&val2=%22Test+f%C3%B6r+V%C3%A4ster%C3%A5s%22"
Strangely enough, when I copy paste the long URL in the bat file in to the IE it won't work. I just get to the website but no result. But if I copy paste it again, it works! All nice lettering and results and all. I hadn't realize it before that entering the URL twice in the IE gives me the proper results.
Edit 2: After much appreciated help, I looked at what was sent in the task manager, which seemed to open okay with "IEXPLORE.EXE ". But there is a difference between the URL I print in my log before I send to the ProcessBuilder
and the command in the task manager. The URL seems to be cut off for some reason since there is no val2
!
Edit 3 + solution: I suspect the edit 2 problem is due to limited amount of characters, because my URL is very long. For anyone out there who will wonder what I did to make it all work: I changed from ProcessBuilder() to another solution, inserted below, which made it all work. Now I just have to figure out why I need to enter the URL twice to get the proper results.
Desktop.getDesktop().browse(new URL(urlStr).toURI());