[英]Create a process in Java bean, get the output and return to web page
Suppose I have a java bean named "Mainbean", which is used to handle a request from web page. 假设我有一个名为“Mainbean”的java bean,它用于处理来自网页的请求。
I want to create a process "proc" in this bean, and get the output of proc, return them to the web page asynchronously, and show them in a inputTextArea in JSF. 我想在这个bean中创建一个进程“proc”,并获取proc的输出,将它们异步返回到网页,并在JSF的inputTextArea中显示它们。
Since "proc" may has so many lines of output, I want to return them line by line and real-time, but not show all them after the process finished. 由于“proc”可能有如此多的输出行,我想逐行和实时地返回它们,但是在过程结束后不会显示它们。
I used following code to create a process and try to get the output. 我使用以下代码创建进程并尝试获取输出。 But it seems like the process failed to exit normally, cause the exit value always be -1.
但似乎进程无法正常退出,导致退出值始终为-1。
builder = new ProcessBuilder("java", "-Xms1024m","-Xmx1024m","-Xss65536k","-cp ",spaceMaker,"SmartBridge", solution," ",this.specFile,"1000000");
proc = builder.start();
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
returnValue = proc.waitFor();
while ((line = br.readLine()) != null) {
// Outputs your process execution
System.out.println(line);
this.metaOutput = this.metaOutput.concat(line);
exit = proc.exitValue();
if (exit == 0) {
// Process finished
break;
}
return output;
}
And in JSF page, I use following code: 在JSF页面中,我使用以下代码:
<h:form>
<h:inputTextarea id="processOutput" value="#{mainBean.metaOutput}" cols="80" rows="20">
<f:ajax render="processOutput"/>
</h:inputTextarea>
</h:form>
My question is: How can I use these technology to meet my requirement in high-level? 我的问题是:我如何使用这些技术来满足我在高级别的要求? Of course, code examples will help me definitely.
当然,代码示例肯定会对我有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.