JSF参数传递方式之三:通过session(application)对象传递
页面到Bean的参数传递
页面中设置参数:
页面到页面的参数传递
页面中设置参数:
页面中设置参数:
- <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>
<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>
后台取参数:
- 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");
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:outputLink value="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:outputText value="#{sessionScope.name}"></h:outputText><br>
- <h:outputText value="#{applicationScope.id}"></h:outputText>