servlet中getLocalPort()和getServerPort()之间的区别 [英] Difference between getLocalPort() and getServerPort() in servlets

查看:841
本文介绍了servlet中getLocalPort()和getServerPort()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究servlet,我想出了 getLocalPort() getServerPort()之间的区别。 。
这里 getLocalPort()表示服务器端只有 getServerPort()的含义?

I am studying servlets, I have come up with a doubt difference between getLocalPort() and getServerPort(). Here the getLocalPort() means server side only then whats the meaning of getServerPort()?

谢谢。

推荐答案

在一个简单的设置中(你的应用服务器/ servlet容器直接接受客户端的请求)两个方法都将返回相同的值。

In a simple setup (where your application server/servlet container accepts the request of the client directly) both methods will return the same value.

当servlet容器不是接受客户端请求的应用程序时(例如你使用带有mod_jk的Apache HTTP服务器接受请求并通过AJP将请求转发给Tomcat实例,然后 getServerPort() 将返回客户端连接的端口(可能是80,当使用默认端口)和 getLocalPort() 将返回por Tomcat用于接受来自HTTP服务器的连接(可能是8009或类似的东西)。

When the servlet container is not the application that accepts the client request (for example when you use an Apache HTTP server with mod_jk to accept the request and forward the request to a Tomcat instance via AJP), then getServerPort() will return the port the client connected to (probably 80, when the default port is used) and getLocalPort() will return the port that Tomcat used to accept the connection from the HTTP server (probably 8009 or something similar).

这篇关于servlet中getLocalPort()和getServerPort()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆