Servlet doFilter setAttributes 在 Servlet 中不可用
我试图在将请求传递给 Servlet 之前通过 doFilter
添加一个属性,以便在 JSTL 中设置一个值。我只是在过滤器中执行 req.setAttribute("b", "blah")
,但它似乎没有在 JSTL 文件中设置。我该怎么做?
I'm trying to add an Attribute to the request via doFilter
before passing it to the Servlet, so that a value in JSTL will be set. I simply do req.setAttribute("b", "blah")
in the filter, but it doesn't seem to get set in the JSTL file. How would I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(2)
白况2024-12-27 08:46:06
问题是 doFilter
方法使用 ServletRequest
而不是具有 setAttribute
方法的 HttpServletRequest
。我的大多数过滤器都是这样的:
public void doFilter(ServletRequest servletRequest,
ServletResponse servletResponse,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
// do what you must...
chain.doFilter(servletRequest, servletResponse);
}
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如果不查看代码,很难查明根本原因。有几种可能的原因。
顺便说一下,不存在“JSTL 文件”这样的东西。也许您的意思是“JSP 文件”。
It's hard to pinpoint the root cause without seeing the code. There are several possible causes.
By the way, there's no such thing as a "JSTL file". Perhaps you meant "JSP file".