简体   繁体   English

如何将变量从Java程序传递到通过启动的浏览器访问的JSP页面?

[英]How to pass variable from Java program to JSP page accessed via launched browser?

I have a simple Java class in which I invoke a call to a JSP page, by launching a browser. 我有一个简单的Java类,其中通过启动浏览器来调用对JSP页面的调用。 I have this part working, but now I want to pass variables from the simple Java class to the JSP page. 我已经完成了这部分的工作,但是现在我想将变量从简单的Java类传递到JSP页面。 How can I do that? 我怎样才能做到这一点?

Here is my code: 这是我的代码:

public static void openURL(String url) {
    String osName = System.getProperty("os.name");
    if (osName.startsWith("Windows")) {
        Runtime.getRuntime().exec(
                "rundll32 url.dll,FileProtocolHandler " + url);
    } else {
        String[] browsers = { "firefox", "opera", "konqueror", "epiphany",
                "mozilla", "netscape" };
        String browser = null;
        for (int count = 0; count < browsers.length && browser == null; count++) {
            if (Runtime.getRuntime()
                    .exec(new String[] { "which", browsers[count] })
                    .waitFor() == 0) {
                browser = browsers[count];
            }
        }
        Runtime.getRuntime().exec(new String[] { browser, url });
    }
}

Please help me. 请帮我。

If you call the JSP page through HTTP (I guess so), then you have to send the variables using GET or POST parameters. 如果您通过HTTP调用JSP页面(我想是这样),则必须使用GET或POST参数发送变量。

For example, if your JSP page's URL is http://localhost:8080/webapp/my.jsp , you can call: 例如,如果您的JSP页面的URL是http:// localhost:8080 / webapp / my.jsp ,则可以调用:

http://localhost:8080/webapp/my.jsp?param1=value1&param2=value2 

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

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