开发者

Socket and JSP application

I am building an application which takes some parameters from jsp and send these parameter to another server using socket. After getting respon开发者_JAVA百科se 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.


After getting response i have to be in continous listen mode. How can I update the jsp with response(which comes from another server).

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜