示例:
当前url:http://localhost:8080/Example/AServlet?username=zhangsan
- getServerName():获取服务器名;
localhost - getServerPort():获取服务器端口号;
8080 - getContextPath():获取项目名;
/Example - getServletPath():获取Servlet路径;
/AServlet - getQueryString():获取参数部分,即问号后面的部分;
username=zhangsan - getRequestURI():获取请求URI;
/Example/AServlet - getRequestURL():获取请求URL;
http://localhost:8080/Example/AServlet - String request.getRemoteAddr():获取服务器的IP,如localhost对应ip为
127.0.0.1
本文详细解析了HTTP请求中的各个组成部分,包括服务器名、端口号、项目名、Servlet路径、参数部分、请求URI和URL等,帮助读者深入理解HTTP请求的工作原理。
1万+

被折叠的 条评论
为什么被折叠?



