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>
<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>
后台取参数:
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");
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");

页面到页面的参数传递
页面中设置参数:
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>
<h:form>
			<%session.setAttribute("name","hujilie"); %>
			<%application.setAttribute("id","123456"); %>
			<h:outputLink value="param2.jsf">Test10</h:outputLink>
	</h:form>
页面中取参数:
Java代码 复制代码
  1. <h:outputTextvalue="#{sessionScope.name}"></h:outputText><br>
  2. <h:outputTextvalue="#{applicationScope.id}"></h:outputText>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值