通过cookie获取客户端环境信息
几天前我刚刚开始使用 Java servlet。我正在尝试开发一个程序,只是为了练习并了解我们可以使用 Java servlet 做什么。
尝试使用一个程序来生成 cookie 并将其发送回客户端作为响应。 发回 cookie 并获取 cookie 信息是可以的,但我想做的是,我们是否可以使用 cookie 获取有关客户端环境的信息,以及我们是否可以使用 cookie 获取浏览器信息,例如哪个浏览器、其版本、操作系统等。
我知道它们存储状态信息,因为 HTTP 是无状态的。所以我只是想知道并尝试是否有一种方法可以通过servlet中的cookie获取客户端的环境信息和浏览器信息。
I just started with Java servlets few days ago. I am trying to develop a program just for practice and to get to know the the stuff we can do with Java servlets.
Trying to have a program that generates a cookie and sends it back to the client in response.
Sending back the cookie and getting cookie info back is fine, but what I want to do is that can we get information about the clients environment using cookies as well as can we get the browser information using cookies, such as which browser, its version, OS, etc.
I know they store state information since HTTP is stateless. So I was just wondering and trying is there a way to get client's environment information and browser information by cookies in servlets.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Cookie 并非旨在获取客户信息。您必须使用
javax.servlet.http.HttpServletRequest
方法 -getHeader()
或getHeaders()
方法来读取请求标头键值。想要获取
user-agent
键的值。Cookies are not designed to get client information. You have to use
javax.servlet.http.HttpServletRequest
methods -getHeader()
orgetHeaders()
method to read request header key-value.Want to get value of
user-agent
key.请访问此链接
Please visit this link