JSF参数传递方式之三:通过session(application)对象传递

JSF参数传递方式之三:通过session(application)对象传递

页面到Bean的参数传递
页面中设置参数:
Java代码
  1. <h:form>
  2. <%session.setAttribute("name","hujilie");%>
  3. <%application.setAttribute("id","123456");%>
  4. <h:commandButtonvalue="Test8"action="#{paramBean.test2}"></h:commandButton>
  5. <h:commandLinkvalue="Test8"action="#{paramBean.test2}"></h:commandLink>
  6. </h:form>
后台取参数:
Java代码
  1. FacesContextcontext=FacesContext.getCurrentInstance();
  2. MapsessionMap=context.getExternalContext().getSessionMap();
  3. MapapplicationMap=context.getExternalContext().getApplicationMap();
  4. HttpSessionsession=(HttpSession)context.getExternalContext().getSession(true);
  5. ServletContextapplication=(ServletContext)context.getExternalContext().getContext();
  6. sessionMap.get("name");
  7. applicationMap.get("id");
  8. session.getAttribute("name");
  9. application.getAttribute("id");

页面到页面的参数传递
页面中设置参数:
Java代码
  1. <h:form>
  2. <%session.setAttribute("name","hujilie");%>
  3. <%application.setAttribute("id","123456");%>
  4. <h:outputLinkvalue="param2.jsf">Test10</h:outputLink>
  5. </h:form>
页面中取参数:
Java代码
  1. <h:outputTextvalue="#{sessionScope.name}"></h:outputText><br>
  2. <h:outputTextvalue="#{applicationScope.id}"></h:outputText>

你可能感兴趣的:(application)