前端获取运行时路径

依赖;

    <dependency>
        <groupId>com.jcraft</groupId>
        <artifactId>jsch</artifactId>
        <version>0.1.55</version>
    </dependency>

后端:
import com.cosmosource.model.socketio.ResultModel;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
public class IPandPortPath {
/**
* 功能描述:获取IP和port根路径
*
* @param httpServletRequest
* @return
*/
private static Logger logger = LoggerFactory.getLogger(WebSocketTest.class);
@RequestMapping(value = “/getIPandPortPath”, produces = “application/json;charset=UTF-8”)
@ResponseBody
public ResultModel getIPandPortPath(HttpServletRequest httpServletRequest) {
Map<String, Object> resultMap = new HashMap<String, Object>();
String scheme = httpServletRequest.getScheme();
String serverName = httpServletRequest.getServerName();
String localPort = String.valueOf(httpServletRequest.getLocalPort());
String direPath = serverName + “:” + localPort;
logger.info("[getIPandPortPath] parms:direPath=[{}]", direPath);
if (StringUtils.isBlank(direPath)) {
logger.error("[getIPandPortPath] 获取IP和port根路径失败,direPath=[{}]", direPath);
return new ResultModel(ResultModel.PARAM_ERROR, “参数错误”, new HashMap<>());
}
resultMap.put(“IPandPortPath”, direPath);
logger.info("[getIPandPortPath] 获取IP和port根路径成功,direPath=[{}]", direPath);
return new ResultModel(ResultModel.RESULT_OK, “获取IP和port根路径成功”, resultMap);
}
}

前端:

var IPandPortPath = null;
Ext.Ajax.request({
async: false,
method: “GET”,
url: “getIPandPortPath”,
defaultPostHeader: “application/json;charset=utf-8”,
params: {}
,
success: function (response, opts) {
var data = Ext.decode(response.responseText);
var resultList = data.data;
IPandPortPath = resultList.IPandPortPath;
//getSessionStateWebsocket();
},
failure: function (response, opts) {
Ext.Msg.alert(‘提示’, ‘获取classPath根路径失败!’, Ext.emptyFn);
}
});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值