获取客户端的IP地址对于Web服务 [英] Getting the IP Address Of A client For a webservice

查看:342
本文介绍了获取客户端的IP地址对于Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JAX-WS,但我在检索使用Web服务的客户端信息时遇到问题。我已经找到了如何使用JAX-RPC和Apache Tomcat Axis,但没有使用JAX-WS。有没有人对此有所了解?

I am using JAX-WS and I am having trouble retrieving the client information that is consuming a webservice. I've found out how to do it with JAX-RPC, and Apache Tomcat Axis, but not with JAX-WS. Does anyone have an idea about this?

推荐答案

这是怎么回事:

@WebService
public class MyService {

  @Resource
  WebServiceContext wsContext; 

  /**
   * Web service operation
   */ 
  @WebMethod 
  public String myMethod() { 

    MessageContext mc = wsContext.getMessageContext();
    HttpServletRequest req = (HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST); 
    System.out.println("Client IP = " + req.getRemoteAddr()); 

  }

} 

这篇关于获取客户端的IP地址对于Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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