JBoss AS 7,Java EE 6如何获取客户端IP? [英] JBoss AS 7, Java EE 6 how to get clients IP?
问题描述
我有一个简单的问题,但是我正在寻找更长的时间,但是我总是找到相同的答案,但我真的不知道该如何处理...
I have a simple question, but I'm searching for longer time, but I always found the same answers,which i don't really know how to handle...
当他注册到我的应用程序时,我想获得客户端的IP地址...
i want to get the IP adress of the client, when he registers to my application...
我发现了这样的东西:
@ManagedBean(name="testController")
@SessionScoped
public class TestController implements Serializable {
private static final long serialVersionUID = -3244711761400747261L;
protected final HttpServletRequest req;
public TestController(HttpServletRequest req) {
this.req = req;
System.out.println(this.req.getRemoteAddr().toString());
}
}
但是我在构造函数中没有HttpServletRequest.... 还是我不知道如何使用它,我得到的只是错误....
but i don't have the HttpServletRequest in the constructor.... or i don't know how to use it, all i get are errors....
推荐答案
Note that you're making one major conceptual mistake in your initial attempt. You're attempting to assign the current HTTP request as a property of a session scoped managed bean. The HTTP request instance will expire by the end of the current HTTP response and thus not be valid anymore and throw exceptions in all colors when you try to access its methods in the subsequent requests following the initial request when the session scoped bean was been created.
这篇关于JBoss AS 7,Java EE 6如何获取客户端IP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!