Socket 和 JSP 应用程序
我正在构建一个应用程序,它从 jsp 获取一些参数并使用套接字将这些参数发送到另一个服务器。得到回应后,我必须处于连续监听模式。如何使用响应(来自另一台服务器)更新jsp。
a.jsp --> 请求 b.jsp。在 b.jsp 中,它调用初始化与另一个服务器的调用。在 b.jsp 函数中它得到响应。但是如何在jsp页面上显示呢?
I am building an application which takes some parameters from jsp and send these parameter to another server using socket. After getting response I have to be in continuous listen mode. How can I update the jsp with response(which comes from another server).
a.jsp -->request to b.jsp. In b.jsp it call initialise the call with another server. In b.jsp function it gets response. But how can I show on jsp page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是可以完成的,但很可能在某个时间点后失败,或者由于客户端/浏览器断开连接,或者服务器断开连接,或者中间节点断开连接。这些超时的持续时间仅在一定程度上是确定性的(但通常约为几秒);在可靠地预测该值之前,应该知道网络中的所有节点。
失败还有其他原因 - 应用程序服务器可以配置为禁止从 servlet 容器连接到其他服务器,或者服务器可能简单地终止线程上的任何进一步处理,怀疑线程被卡住(并且不会响应) )。
如果您决定继续,尽管有上述失败警告,那么实现此操作的机制是在 JSP 页面中实现一个循环,该循环侦听您创建的此套接字并将响应发布到客户端,就像您通常所做的那样。
如果您希望以故障安全的方式执行此操作,请使用 AJAX,因为我怀疑您不打算刷新 JSP 页面。
This can be done, but is most likely bound to fail after some point in time, either due to the client/browser dropping the connection, or the server dropping the connection, or an intermediate node dropping the connection. The duration of these timeouts is deterministic only to a certain extent (but is often in the order of a few seconds); all the nodes in the network ought to be known before predicting this value reliably.
There are other reasons for failure too - the application server could be configured to disallow connections to other servers from the servlet container, or the server may simply terminate any further processing on the thread under the suspicion that the thread is stuck (and will not respond).
If you have decided to proceed despite the above caution of failure, then the mechanism to implement this is to implement a loop in the JSP page that listens on this socket that you've created and posts the response to the client as you would normally do.
If you wish to do this in a fail-safe manner, use AJAX, for I suspect that you do not intend to have the JSP page refreshed.
从jsp中,创建一个HttpURLConnection,并获取HttpURLConnection的输入流。从inputsream中读取数据并将其写入jsp writer。
您可以编写自定义标签来执行此操作。或者,检查是否已存在。
From the jsp, create a HttpURLConnection,and get the inputstream of the HttpURLConnection. Read the data from the inputsream and write it to the jsp writer.
You can write a custom tag to do this. Or, check if one already exists.