I found a workaround that solves it. He abuses the fact that from the browser you can redirect to another page with the parameters, even if the landing page is local.
Instead of calling the url directly from Java, do the following:
Create a temporary HTML file. In this temporary file, type in the HTML code that automatically redirects the browser to the real URL that you want to open. Example:
<meta http-equiv="refresh" content="0; url=file:///C:/work/my_page.html?message=helloWorld" />
Then just launch the browser in the HTML temp file, which immediately redirects you to the real URL :)
Here is the Java code for this in one line:
String url = "file:///C:/work/my_page.html?"; String params = "message=HelloWorld"; Desktop.getDesktop().browse(new URI(createHtmlLauncher(url + params)));
createHtmlLauncher() method:
private String createHtmlLauncher(String targetUrl) throws Exception { String launcherFile = System.getProperty("java.io.tmpdir") + "local_launcher.html"; File launcherTempFile = new File(launcherFile); PrintWriter writer = null; try { writer = new PrintWriter(launcherTempFile, "UTF-8"); } catch (Exception e) { throw new Exception("Error opening file for writing: " + launcherTempFile.getAbsolutePath() + " : " + e.getMessage()); } writer.println("<meta http-equiv=\"refresh\" content=\"0; url=" + targetUrl + "\" />"); writer.close(); return "file:///" + launcherFile.replace("\\", "/"); }
Please note that to avoid filling the disk with a large number of temporary files, this code uses the same file for redirection each time. This means that if you open multiple pages without any delay, you are likely to have problems with race.
The solution is to use the generated temp file instead. The disadvantage of this is that you cannot know when to delete these files from disk. If you do not delete them, and you have extreme use of this function, the disk may be full.
source share