我是靠谱客的博主 开放画板,最近开发中收集的这篇文章主要介绍SSH框架action中获取服务器端ip,端口,项目名,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述


获取服务器端:

"http://"
+ org.apache.struts2.ServletActionContext.getRequest()
.getLocalAddr()
+ ":"
+ org.apache.struts2.ServletActionContext.getRequest()
.getServerPort()     


+ org.apache.struts2.ServletActionContext.getRequest()
.getContextPath();



本地测试结果为:http://127.0.0.1:8080/pojectTest/


action中获取request

ServletActionContext.getRequest();



获取客户端ip地址方法

  1.   public String getIpAddr(HttpServletRequest request) {     
  2.       String ip = request.getHeader("x-forwarded-for");     
  3.       if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {     
  4.          ip = request.getHeader("Proxy-Client-IP");     
  5.      }     
  6.       if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {     
  7.          ip = request.getHeader("WL-Proxy-Client-IP");     
  8.       }     
  9.      if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {     
  10.           ip = request.getRemoteAddr();     
  11.      }     
  12.      return ip;     
  13. }   



最后

以上就是开放画板为你收集整理的SSH框架action中获取服务器端ip,端口,项目名的全部内容,希望文章能够帮你解决SSH框架action中获取服务器端ip,端口,项目名所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(42)

评论列表共有 0 条评论

立即
投稿
返回
顶部