How does Java Servlet and container actually works at each layer of Open Systems Interconnection model (OSI model)? Does the servlet container internally use operating system's native socket libraries via JNI? Is there even any other possibility for JVM to use networking?

- 303,325
- 100
- 852
- 1,154

- 21,690
- 47
- 129
- 225
-
I think so. Java servlets run on top of Java/JVM, and Java calls native sockets. Since a network requires a physical layer, I'm not sure anything else is possible. Any new devices would have to go through the OS layer, and would look to Java/JVM just like another network. Routing directs which network you connect to; as far as I know that works solely via IP address. – markspace Dec 23 '17 at 17:48
-
2The OSI model (a) is obsolete and (b) doesn't apply to TCP/IP, which has its own, prior model. A Java Servlet and container and indeed JVM runs in the application layer. – user207421 Dec 23 '17 at 17:55
-
@EJP I didn't know the OSI mode was obsolete; but I don't mind I never really liked that thing anyway. My understanding was that OSI was just the TCP/IP stack with a Presentation and Application layer glomped on top of it. OSI didn't really add a lot of value to the whole networking concept. – markspace Dec 23 '17 at 18:24
-
But "Please Do Not Throw Sausage Pizza Away" is valuable asset, which is why I prefer OSI model over TCP/IP model – Tuomas Toivonen Dec 23 '17 at 20:31
-
1It's a pointless exercise to attempt to shoehorn TCP/IP into the OSI model. It would make more sense to try and shoehorn OSI into TCP/IP since the world runs TCP/IP and nobody and nothing runs a networking stack based on the OSI model. – President James K. Polk Dec 23 '17 at 23:38
-
@markspace The OSI model (1984) refers to the OSI protocol stack. When did you last use one of those? When did you ever? The TCP/IP model (1974) refers to the TCP/IP protocol stack, and predates OSI by a considerable margin. Unfortunately during the OSI propaganda phase of the 1980s, when we got it shoved down our throats day and night, and there were government projects to adopt it, etc. etc., some people decided to use it as a universal model for teaching, which it isn't and was never intended to be, and they haven't stopped. It is more than high time to let it rest in peace. – user207421 Dec 24 '17 at 00:52
-
_Nothing_ works in the OSI model because none of the OSes have implemented the OSI model. It is just a model. The IP Services model is closer to the real world, but it, too, is just a model, and there are things that do not adhere to it. – Ron Maupin Jul 23 '20 at 02:36
1 Answers
The OSI model works great in theory as a guideline, but in practice is not always possible or easy to classify or separate the inner workings and protocols of a complex system in each of its layers. To better understand the protocol architecture of, for instance, a Java Servlet, it is much better to use the TCP/IP model since it is simpler than the OSI model.
Starting with the Link Layer, it has the task to translate an IP address to a MAC or physical address. The most famous protocol in this layer is the Ethernet. It mainly operates inside an Ethernet network card.
Next we have the Network and the Transport Layer, where we find the IP and TCP protocols, respectively. Both protocols are usually supported by the host operating system using a networking application programming interface (API). The most popular API is called sockets. In the case of Java, its objects have an underlying implementation that interfaces to native code (according to these sources: 1, 2, and 3).
And finally there's the Application layer, where we find the HTTP protocol. This protocol is implemented and supported by the application servers, such as Tomcat, JBoss and Glassfish.
Reference: This answer was based on the book TCP/IP Illustrated book, by Kevin R. Fall

- 1,059
- 14
- 32