简体   繁体   English

Java用querystring打开网页

[英]java open web page with querystring

I need to open web page after clicking button in my java window app. 我需要在Java窗口应用中单击按钮后打开网页。 My problem is that when I use 我的问题是当我使用

URI testPage = new URI("file:///C:/index.html?param1&param2"); Desktop.getDesktop().browse(testPage);

opened page in my browser doesn't contain my querystring parameters, which are necessary to display page properly. 在浏览器中打开的页面不包含我的querystring参数,这是正确显示页面所必需的。 How can I do that? 我怎样才能做到这一点? Why is everything after "?" 为什么在“?”之后的所有内容? cut? 切?

I don't think a file URI supports a query string. 我认为文件URI不支持查询字符串。 The query string is handled by the HTTP server, so unless you are running a server on your computer I don't think it will work. 查询字符串由HTTP服务器处理,因此,除非您在计算机上运行服务器,否则我认为它不会起作用。

Look for similar issues 寻找类似的问题

Your problem isn't in how java handles query strings, it is in how you local browser is handling file requests. 您的问题不在于Java如何处理查询字符串,而在于本地浏览器如何处理文件请求。 A quick test of an HTTP URL shows that this works just fine. 对HTTP URL进行的快速测试表明,此方法很好用。 I tried this and it worked exactly as expected: 我尝试了一下,它完全按预期工作:

public class Test {
    public static void main(String[] args) throws IOException, URISyntaxException{
        URI test = new URI("http://google.com?test=monkey");
        Desktop.getDesktop().browse(test);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM