JSF参数传递方式之三:通过session(application)对象传递
页面中设置参数:
- <h:form>
- <%session.setAttribute( "name" , "hujilie" );%>
- <%application.setAttribute( "id" , "123456" );%>
- <h:commandButtonvalue= "Test8" action= "#{paramBean.test2}" ></h:commandButton>
- <h:commandLinkvalue= "Test8" action= "#{paramBean.test2}" ></h:commandLink>
- </h:form>
- FacesContextcontext=FacesContext.getCurrentInstance();
- MapsessionMap=context.getExternalContext().getSessionMap();
- MapapplicationMap=context.getExternalContext().getApplicationMap();
- HttpSessionsession=(HttpSession)context.getExternalContext().getSession( true );
- ServletContextapplication=(ServletContext)context.getExternalContext().getContext();
- sessionMap.get( "name" );
- applicationMap.get( "id" );
- session.getAttribute( "name" );
- application.getAttribute( "id" );
页面到页面的参数传递
页面中设置参数:
- <h:form>
- <%session.setAttribute( "name" , "hujilie" );%>
- <%application.setAttribute( "id" , "123456" );%>
- <h:outputLinkvalue= "param2.jsf" >Test10</h:outputLink>
- </h:form>
- <h:outputTextvalue= "#{sessionScope.name}" ></h:outputText><br>
- <h:outputTextvalue= "#{applicationScope.id}" ></h:outputText>