如何使用 Struts 2 在 JSP 上获取 User-Agent 标头

发布于 2024-12-27 02:37:08 字数 59 浏览 6 评论 0原文

如何使用 Struts 2 获取 JSP 上的 User-Agent 标头?

提前致谢!

How can I obtain the User-Agent header on JSP, using Struts 2?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久光 2025-01-03 02:37:08

如果我的假设是正确的,您希望 User-Agent 标头来处理多个视图,例如桌面和移动设备(仅假设)

有多种方法可以查找有关使用代理的详细信息。我想到的一种简单方法是简单的 JSTL,

<c:set var="user-agent" value="${header['User-Agent']}" scope="session"/>

另一种是纯JSP代码

String user_agent = request.getHeader("user-agent");

,如果我的假设是正确的,最好的解决方案是创建一个 拦截器< /a> 可以改变返回值基于客户端的用户代理的代码。

可以根据您的要求提供任何其他输入。

If my assumptions are right you want to have the User-Agent header to deal with multiple view say desktop and mobile (only assumption)

There are various way to find details about use agent.One easy way came to my mind is simple JSTL

<c:set var="user-agent" value="${header['User-Agent']}" scope="session"/>

another is plain JSP code

String user_agent = request.getHeader("user-agent");

and if my assumption is right the best possible solution is to create an interceptors that can change the return code based on the user-agent of the client.

Any other inputs can be provided based on your requirements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文