JavaWeb 获取请求网络协议、IP、端口号、项目根路径
JavaWeb 获取请求网络协议、IP、端口号、项目根路径
CreateTime--2018年6月1日16点32分
Author:Marydon
1.需求
在项目中,需要使用Java向本程序发送request请求,由于项目的发布名称、部署IP和端口不固定,
如何才能动态获取这些信息呢?
2.代码实现
import javax.servlet.http.HttpServletRequest;
/**
* 获取url请求前缀
* @explain http://localhost:8080/test
* @param request request对象
* @return
*/
public static String getRequestPrefix (HttpServletRequest request) {
// 网络协议
String networkProtocol = request.getScheme();
// 网络ip
String ip = request.getServerName();
// 端口号
int port = request.getServerPort();
// 项目发布名称
String webApp = request.getContextPath();
String urlPrefix = networkProtocol + "://" + ip + ":" + port + webApp;
return urlPrefix;
}
JavaWeb 获取请求网络协议、IP、端口号、项目根路径的更多相关文章
- js 获取请求网络协议、IP、端口号、项目名称
js 获取请求网络协议.IP.端口号.项目名称 CreationTime--2018年6月19日15点54分 Author:Marydon /** * 获取url请求前缀 * @return ht ...
- 服务器使用nginx做代理,通过HttpServletRequest获取请求用户真实IP地址
首先,在nginx配置中添加如下配置 server { listen ; server_name www.wenki.info; #要访问的域名 charset utf8; location / { ...
- 【RL-TCPnet网络教程】第22章 RL-TCPnet之网络协议IP
第22章 RL-TCPnet之网络协议IP 本章节为大家讲解IP(Internet Protocol,网络协议),通过前面章节对TCP和UDP的学习,需要大家对IP也有个基础的认识. (本章 ...
- js获取网站项目根路径
//js获取项目根路径,如: http://localhost:8083/uimcardprj function getRootPath(){ //获取当前网址,如: http://localhost ...
- js获取项目根路径
//js获取项目根路径,如: http://localhost:8083/uimcardprj function getRootPath(){ //获取当前网址,如: http://localhost ...
- 在HTML页面中获取当前项目根路径的方法
在HTML页面获取项目根路径的方法: function getRootPath(){ var curPageUrl = window.document.location.href; var rootP ...
- js获取当前项目根路径URL (转自CSDN 红领巾-sunlight)
/** * //获取当前项目根路径 * @return {TypeName} */ function getRootPath(){ //获取当前网址,如: http://localhost:8083/ ...
- Java中获取项目根路径和类加载路径的7种方法
引言 在web项目开发过程中,可能会经常遇到要获取项目根路径的情况,那接下来我就总结一下,java中获取项目根路径的7种方法,主要是通过thisClass和System,线程和request等方法. ...
- html 获取项目根路径
html 获取项目根路径 function getContextPath(){ var pathName = document.location.pathname; //当前文件的绝度路径 var i ...
随机推荐
- lightoj 1296 - Again Stone Game 博弈论
思路:由于数据很大,先通过打表找规律可以知道, 当n为偶数的时候其SG值为n/2; 当n为奇数的时候一直除2,直到为偶数m,则SG值为m/2; 代码如下: #include<stdio.h> ...
- Struts+HIbernate+Spring
1.Struts 取代JSP中的控制功能,为系统添加独立的控制,采用Struts引入标签,实现JSP与后台JAVA代码的分离,JSP只负责显示,与struts.xml配合实现页面跳转 实现:接收请求, ...
- Dual transistor improves current-sense circuit
In multiple-output power supplies in which a single supply powers circuitry of vastly different curr ...
- 将dll文件注入到其他进程中的一种新方法
http://www.45it.com/windowszh/201212/33946.htm http://www.hx95.cn/Article/OS/201212/65095.html 我们知道将 ...
- 资源合并fis-postpackager-simple插件的使用
FIS默认只会进行文件打包,不会对页面中的静态资源引用进行替换,这时可以利用fis-postpackager-simple插件进行资源替换. 安装: npm install -g fis-postpa ...
- scp遇到路径中有空格
sudo scp root@1.1.1.1:/test/soft/123/Microsoft SQL Server 2000.iso . 错误! sudo scp root@1.1.1.1: ...
- Guava的使用
package guava; import java.io.File; import java.io.IOException; import java.util.ArrayList; import j ...
- poj 1330 Nearest Common Ancestors 题解
Nearest Common Ancestors Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24618 Accept ...
- Android内存调试命令
adb shell dumpsys meminfo 包名 比如: adb shell dumpsys meminfo cn.com.test
- SQL OUTER JOIN
When we want to select out all the record from two table, no matter it's present at second table or ...