据我所知JSF,默认使用forward来处理页面导航,但是为什么requestScope [“javax.servlet.forward.request_uri”]返回null(不显示在outcome.xhtml页面中)。以下是示例代码:
的index.xhtml
<h:body>
<h1>Index page</h1>
<h1>Request URI: #{request.requestURI}</h1>
<h1>Forward Request URI: #{requestScope['javax.servlet.forward.request_uri']}</h1>
<h1>Forward Servlet Path: #{requestScope['javax.servlet.forward.servlet_path']}</h1>
<h:form>
RequestScoped input: <h:inputText value="#{requestScopedBean.input}" />
<h:commandButton value="submit" action="#{requestScopedBean.submit}" />
</h:form>
</h:body>
outcome.xhtml
<h:body>
<h1>Outcome page</h1>
<h1>Request URI: #{request.requestURI}</h1>
<h1>Forward Request URI: #{requestScope['javax.servlet.forward.request_uri']}</h1>
<h1>Forward Servlet Path: #{requestScope['javax.servlet.forward.servlet_path']}</h1>
<h1>Requestscoped output: <h:outputText value="#{requestScopedBean.input}" /></h1>
RequestScopedBean.java
@Named
@RequestScoped
public class RequestScopedBean {
private int id;
private String input;
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
@PostConstruct
public void init() {
Random random = new Random();
id = random.nextInt();
System.out.println(getClass().getName() + " id: " + id);
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String submit() {
System.out.println(getClass().getName() + " invokes submit() method");
System.out.println("input: " + input);
return "outcome";
}
}
答案 0 :(得分:0)
据我所知JSF,默认情况下使用forward来处理页面导航
根据 xhtml 扩展名判断,您正在使用Facelets作为视图定义语言。
如果您使用JSP作为VDL,那么您将是正确的,因为RequestDispatcher.forward是用于将请求从servlet分派到JSP的标准机制。
但是,Facelet视图完全由JSF实现处理,不需要将视图呈现委托给容器。 <{3}}不是必需的。