在正在运行的Java程序的背景上执行一个jsp程序 [英] execute a jsp program on background of a running java program

查看:91
本文介绍了在正在运行的Java程序的背景上执行一个jsp程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



感谢提前好友!希望你能帮助我!...

解决方案

这应该是工作,不能确定它是否服务正常,请向我保证结果

  import java.io.BufferedReader; 
import java.io.IOException;
import java.io.InputStreamReader;
导入org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
导入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响应;
StringBuilder builder = new StringBuilder();
尝试
{
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);


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



$ / code $ / pre

这个java程序执行您的jsp



您必须将此行添加到您的jsp页面中

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

其中OpenId:应用程序名称
asd.html是您的jsp页面,与您从java程序调用的相同的jsp


I just want execute my jsp program when a button on my running java program is clicked, it doesn't need to be visible, the jsp program i am saying is for printing and once it is loaded in the browser it will just pop up the print dialog confirm box, so again it doesn't need to be visible, once the button in my java program is clicked the print dialog will just pop up and that's it. By the way i am new here in this site, and also know only basics of java, so i do not have any idea how to do it, but i like to do it that way and with just a link of the jsp page from the localhost, something like that,

Thanks in advance buddies! Hope you will help me!...

解决方案

this should be working , cant be sure if it serves properly , please assure me the outcome

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();
        } 
    }
}

for this java program to ececute your jsp

you have to add this line in your jsp page

<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

这篇关于在正在运行的Java程序的背景上执行一个jsp程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆