JSF参数传递方式之三:通过session(application)对象传递
页面到Bean的参数传递
页面中设置参数:
页面到页面的参数传递
页面中设置参数:
页面中设置参数:
- <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>
<h:form>
<%session.setAttribute("name","hujilie"); %>
<%application.setAttribute("id","123456"); %>
<h:commandButton value="Test8" action="#{paramBean.test2}"></h:commandButton>
<h:commandLink value="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");
FacesContext context = FacesContext.getCurrentInstance();
Map sessionMap =context.getExternalContext().getSessionMap();
Map applicationMap = context.getExternalContext().getApplicationMap();
HttpSession session =(HttpSession) context.getExternalContext().getSession(true);
ServletContext application = (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:form>
<%session.setAttribute("name","hujilie"); %>
<%application.setAttribute("id","123456"); %>
<h:outputLink value="param2.jsf">Test10</h:outputLink>
</h:form>
页面中取参数:
- <h:outputTextvalue="#{sessionScope.name}"></h:outputText><br>
- <h:outputTextvalue="#{applicationScope.id}"></h:outputText>