0

我只想在单击正在运行的 java 程序上的按钮时执行我的 jsp 程序,它不需要可见,我说的 jsp 程序用于打印,一旦它加载到浏览器中,它就会弹出打印对话框确认框,所以它不需要可见,一旦我的java程序中的按钮被点击,打印对话框就会弹出,就是这样。顺便说一句,我是这个网站的新手,也只知道 java 的基础知识,所以我不知道该怎么做,但我喜欢这样做,只需要一个来自 jsp 页面的链接本地主机,类似的东西,

提前谢谢小伙伴们!希望你能帮助我!...

4

1 回答 1

0

这应该有效,不能确定它是否正常运行,请向我保证结果

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;


    public class callURL {
    public static void main(String[] args) 
    {
        String url = "http://localhost:8080/OpenID/asd.html";
        HttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        HttpResponse response;
        StringBuilder builder= new StringBuilder();
        try 
        {
            response = httpClient.execute(httpPost);
            BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
            char[] buf = new char[8000];
            int l = 0;
                while (l >= 0) 
                {
                    builder.append(buf, 0, l);
                    l = in.read(buf);
                }

        } 
        catch (ClientProtocolException e) 
        {
            e.printStackTrace();
        } 
        catch (IOException e) 
        {
            e.printStackTrace();
        } 
    }
}

这个java程序来执行你的jsp

你必须在你的jsp页面中添加这一行

<script>
window.location.href="http://localhost:8080/OpenID/asd.html"
</script>

where OpenId : Application Name
asd.html is your jsp page , the same jsp which you are calling from java program
于 2013-01-24T06:34:59.433 回答