简体   繁体   English

Java多线程ajax更新

[英]java multithreaded ajax update

I have jsp, which does ajax requests to a controller and passes IP's and shell commands that server will do. 我有jsp,它会向控制器发出ajax请求,并传递服务器将执行的IP和shell命令。 For example, ajax request has params "127.0.0.1", "ls -la, ls". 例如,ajax请求的参数为“ 127.0.0.1”,“ ls -la,ls”。 (commands - is a list) Server executes these commands in separate threads(one thread per IP, or other) and updates table on jsp which contains output data of these commands. (命令-是列表)服务器在单独的线程(每个IP线程一个,或其他线程)上执行这些命令,并更新jsp上的表,其中包含这些命令的输出数据。 So how it can be implemented? 那么如何实现呢? How can I get results from each thread and ajax update table ? 如何从每个线程和Ajax更新表中获取结果?

Thanks! 谢谢!

Your question reads a little like you're using "jsp" to refer to your client code - JSP is a server-side scripting language. 您的问题听起来有点像您在使用“ jsp”来引用您的客户端代码一样-JSP是一种服务器端脚本语言。

That said, and assuming that your JSP (on the server) is using System.exec( ... ) to run the shell commands, that call will actually return a Process object. 也就是说,并假设您的JSP(在服务器上)正在使用System.exec( ... )运行Shell命令,则该调用实际上将返回Process对象。 You'll need to wait for the process to complete, with the waitfor() method, then you can get the output stream off the process and read in the input, parse it, and then echo it out in your JSP. 您需要使用waitfor()方法等待该过程完成,然后才能从该过程中获得输出流,并读入输入,对其进行解析,然后在JSP中将其回显。

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

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