问题描述
什么是防止某人投票两次的最佳方法?我如何获得用户的IP地址?如果他们在大型网络上怎么办?那个网络上的每个人都会显示相同的IP吗?谢谢
whats the best way of preventing someone from voting twice? How do i get the users ip address? What if they are on a large network? will everyone on that network show the same ip? thanks
UPDATE:request.getRemoteAddr()和request.getRemoteHost()返回服务器名称,而不是客户端的主机名和ip。其他人有什么好主意吗?
UPDATE: request.getRemoteAddr() and request.getRemoteHost() return the Server names, not the client's host name and ip. Anyone else got any bright ideas?
好的,所以让我们忘记投票两次。我只是想获取用户的IP地址?我尝试了request.getRemoteAddr()和request.getRemoteHost(),并认为我获取服务器地址。我可以访问两个独立的网络并获得相同的IP地址:(
Ok, so lets forget about the voting twice thing. Im just trying to get the users ip address? i tried request.getRemoteAddr() and request.getRemoteHost() and think im getting the servers address. I have access to two separate networks and am getting the same IP address :(
推荐答案
在JSP中,使用请求.getRemoteAddr()。这将返回以字符串形式发送请求的代理的IP地址。
In your JSP, use request.getRemoteAddr(). This returns the IP address of the agent that sent the request as a String.
此外, request.getRemoteHost() 将尝试获取完全限定的主机名。如果无法解析名称,则会返回IP地址,如 getRemoteAddr()。
Also, request.getRemoteHost() will attempt to get the fully qualified host name. If it can't resolve the name however, the IP address will be returned as in getRemoteAddr().
这篇关于jsp获取ip地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!