为什么 ${bean.property} 在 JSP 中自动创建一个 bean?
Why does ${bean.property} auto-creates a bean in JSP?
我知道 JSP 已被弃用。
Here,提到
In JSP, the ${} won't autocreate the managed bean when it's not in
scope yet. You can thus only use it if you can guarantee that #{} on
the very same managed bean is been used somewhere before in the
component tree and also take view build time vs view render time
lifecycle into account.
为了检查它是否真实,我想到了这个:
像这样的简单 JSP 页面,
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
</head>
<body>
${myPlayersBean.playerName}
Here
</body>
</html>
哪里
@ManagedBean(name = "myPlayersBean")
@RequestScoped
public class PlayersBean {
private String playerName = "Rafael";
// getters & setters
}
它在命中时输出 http://localhost:8080/Leonard/faces/create.jsp
:
Rafael Here
请推荐?
这条语句,
In JSP, the ${} won't autocreate the managed bean when it's not in scope yet
仅在您使用 JSF 1.1 或更早版本或使用 JSP 2.0 或更早版本时适用。从 JSF 1.2 和 JSP 2.1 开始,JSF EL 为 unified with JSP EL and that's why it started to work (via javax.el.CompositeELResolver
).
尽管如此,不建议使用 ${...}
访问 JSF 托管 bean。它是不可写的,而 #{...}
是可写的,所以你真的需要在输入组件中使用 #{...}
。在同一个 JSF 页面中混合使用 ${...}
和 #{...}
可能最终会混淆未来的代码 readers/maintainers.
我知道 JSP 已被弃用。
Here,提到
In JSP, the ${} won't autocreate the managed bean when it's not in scope yet. You can thus only use it if you can guarantee that #{} on the very same managed bean is been used somewhere before in the component tree and also take view build time vs view render time lifecycle into account.
为了检查它是否真实,我想到了这个:
像这样的简单 JSP 页面,
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
</head>
<body>
${myPlayersBean.playerName}
Here
</body>
</html>
哪里
@ManagedBean(name = "myPlayersBean")
@RequestScoped
public class PlayersBean {
private String playerName = "Rafael";
// getters & setters
}
它在命中时输出 http://localhost:8080/Leonard/faces/create.jsp
:
Rafael Here
请推荐?
这条语句,
In JSP, the ${} won't autocreate the managed bean when it's not in scope yet
仅在您使用 JSF 1.1 或更早版本或使用 JSP 2.0 或更早版本时适用。从 JSF 1.2 和 JSP 2.1 开始,JSF EL 为 unified with JSP EL and that's why it started to work (via javax.el.CompositeELResolver
).
尽管如此,不建议使用 ${...}
访问 JSF 托管 bean。它是不可写的,而 #{...}
是可写的,所以你真的需要在输入组件中使用 #{...}
。在同一个 JSF 页面中混合使用 ${...}
和 #{...}
可能最终会混淆未来的代码 readers/maintainers.