0

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());

hoxinabox
  • 3
  • 4
  • Okay, the url is enclosed in double quotes which is required here because of `&` in url. The url looks correct encoded. Does the url start with the protocol, i.e. with `http://` or `https://`? Other protocols like `file://` or `ftp://` can be excluded by looking on this url. – Mofi Jan 26 '17 at 06:29
  • Yes, it is a complete url similar to "http://server_name.com/analytics/saw.dll?". The only non ABC characters are &, /, +, =, ? and a punctuation mark. – hoxinabox Jan 26 '17 at 07:15
  • Do you have tried with escaping each percent sign with one more percent sign in your Java application before passing the url to command process? If the url is expanded before calling `iexplore.exe` or `chrome.exe` it is necessary to escape each `%` with one more `%` to get percent sign not interpreted as argument or environment variable reference. – Mofi Jan 26 '17 at 10:25
  • Hint: After Internet Explorer was started by your Java application with the url, press Ctrl+Alt+Del and __Start Task Manager__. Select tab __Processes__. Click in menu __View__ on menu item __Select Columns__. Near the bottom there is __Command Line__. Check this item and close the window with __OK__. Look in list of running processes for __iexplore__ and increase the width of the column __Command Line__ to see the full command line which was used to start Internet Explorer. – Mofi Jan 26 '17 at 10:30
  • I don't enter any percent sign into the URL; that is the URLEncoder that changes Å to a %C3%A5. So I just take the name the user chooses, pass through the encoder and have it in the URL (the answer to the other question I edited in my post) – hoxinabox Jan 26 '17 at 14:13
  • Make sure in your Java application to encode just the url and then enclose the encoded url in double quotes. Otherwise `"` is replaced by `%22` and the url is not enclosed anymore in double quotes. An ampersand found by `cmd.exe` in a not double quoted string is not interpreted as literal character, but as operator, see answer on [Single line with multiple commands using Windows batch file](http://stackoverflow.com/a/25344009/3074564) That would at least explain why everything after first ampersand in url is missing in command line of Internet Explorer. – Mofi Jan 27 '17 at 07:03
  • See also the answer on [Difference in Delayed expansion of ERRORLEVEL on cmd prompt and win32_process](http://stackoverflow.com/a/41735154/3074564). Perhaps it helps to replace in already encoded url all `&` by `^&` to get passed to `iexplore.exe` from `cmd.exe` finally just `&`. But that should not be really necessary if the url is right enclosed in double quotes on starting `cmd.exe` as it looks like by the posted batch file output where you have hopefully not added the double quotes by yourself in the post instead of copying what was really written into the text file. – Mofi Jan 27 '17 at 07:07
  • I suspect that the URL that is shown in the task manager is cut off because of the URLs length: I see that many other commands are cut off now that I've looked and troubleshooted. I tried switching & to ^&, both in cmd and straight in the URL, and neither worked. The double quotes are indeed in the output, which I can also see in the output in my log. I decided to change from ProcessBuilder() to Desktop.getDesktop().browse(new URL(urlStr).toURI()); This made it all work! So I think I'll go with that solution. Thousands of thanks for your help!! – hoxinabox Jan 27 '17 at 13:50

0 Answers0