如何将变量从jsf托管bean传递到jsp页面

发布于 2024-08-30 10:51:06 字数 418 浏览 2 评论 0原文

如何将变量从 JSF 托管 bean 传递到 JSP 页面。

PS:我在门户上下文(liferay)中。

我尝试过:

在托管 Bean 中:

HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();

request.setAttribute("var", "someTxt");

在 JSP 中:

<% 
    String var = (String)request.getAttribute("var");
%> 

我没有得到任何结果。

How can I pass a variable from JSF managed bean to JSP page.

PS: I'm in portal context (liferay).

I tried this:

in Managed Bean:

HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();

request.setAttribute("var", "someTxt");

in JSP:

<% 
    String var = (String)request.getAttribute("var");
%> 

I don't get any result.

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

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

发布评论

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

评论(2

习ぎ惯性依靠 2024-09-06 10:51:06

您必须保持相同的请求 - 即转发,而不是重定向到 jsp。

如果这是不可能的,您可以使用会话而不是请求,但要小心不要在那里存储太多信息。

You have to stay in the same request - i.e. forward, instead of redirect to the jsp.

If this is not possible you may use the session instead of the request, but be careful with storing too much information there.

我一直都在从未离去 2024-09-06 10:51:06

您可以尝试使用 JSF 标签包装您的 scriptlet 代码。

You may try to wrap your scriptlet code with JSF tag.

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