简体   繁体   中英

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. I have this part working, but now I want to pass variables from the simple Java class to the JSP page. 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.

For example, if your JSP page's URL is http://localhost:8080/webapp/my.jsp , you can call:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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