Java 如何从managedBean获取xhtml jsf页面上的会话信息?

Java 如何从managedBean获取xhtml jsf页面上的会话信息?,java,session,jsf,icefaces,Java,Session,Jsf,Icefaces,我的jsp文件中有以下一段代码getSession信息: <jsp:useBean id="bookBean" class="beans.trade.BookBean" scope="session"> <% bookBean.setSession( request.getSession() ); %> </jsp:useBean> 现在我的xhtml页面如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTM

我的jsp文件中有以下一段代码
getSession
信息:

 <jsp:useBean id="bookBean" class="beans.trade.BookBean" scope="session">
    <% bookBean.setSession( request.getSession() ); %>
 </jsp:useBean>
现在我的
xhtml
页面如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:icecore="http://www.icefaces.org/icefaces/core"
      xmlns:ice="http://www.icesoft.com/icefaces/component"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:ace="http://www.icefaces.org/icefaces/components"
      xmlns:p="http://java.sun.com/jsf/core"
      xmlns:ice-cc="http://www.icesoft.com/icefaces-composite-comps">
<h:head>
    <title>bookTemplate</title>
    <link rel="stylesheet" type="text/css" href="/xmlhttp/css/rime/rime.css"/>
</h:head>

<h:body>
    <ice:form>
        <p align="center">
            <ice:outputText value="Book Template" style="text-align:center;font-size:40px;"></ice:outputText>
        </p>
        <br/>
        <br/>

        <p align="center">
            <ice:panelGrid columns="2">
                <ice:panelGrid>
                    <ice:outputText value="Book Name:" style="text-align:left;font-size:20px;"
                                    id="bookName"></ice:outputText>
                </ice:panelGrid>
                <ice:panelGrid>
                    <ice:inputText id="BookNameInputText" style="width: 195px;"
                                   value="#{bookBean.bookName}"></ice:inputText>
                </ice:panelGrid>
            </ice:panelGrid>
        </p>
        <br/>
        <br/>
    </ice:form>
</h:body>
</html>

书模板





因此,我的问题是如何在该页面上获取
会话
信息

更新

我正在调试应用程序,当我尝试获取
initialContext
时,结果是
javax.servlet.ServletException:会话不能为null
引发异常,不确定如何处理该异常

看看你的创业计划


但是,您可以使用java scriplet进行会话,这将违反ICEfaces约定。因此,只要可以通过xhtml文件中的ICEfaces标记访问所有bean数据,就不需要访问任何会话。

尝试引用。正如BalusC所建议的,我使用了
FacesContext context=FacesContext.getCurrentInstance();HttpSession会话=(HttpSession)context.getExternalContext().getSession(true)
并在我的Bean中获得了HTTP会话,并且能够获得会话中存在的用户详细信息。您能否详细说明这将如何真正起作用,因为我对此不太了解。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:icecore="http://www.icefaces.org/icefaces/core"
      xmlns:ice="http://www.icesoft.com/icefaces/component"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:ace="http://www.icefaces.org/icefaces/components"
      xmlns:p="http://java.sun.com/jsf/core"
      xmlns:ice-cc="http://www.icesoft.com/icefaces-composite-comps">
<h:head>
    <title>bookTemplate</title>
    <link rel="stylesheet" type="text/css" href="/xmlhttp/css/rime/rime.css"/>
</h:head>

<h:body>
    <ice:form>
        <p align="center">
            <ice:outputText value="Book Template" style="text-align:center;font-size:40px;"></ice:outputText>
        </p>
        <br/>
        <br/>

        <p align="center">
            <ice:panelGrid columns="2">
                <ice:panelGrid>
                    <ice:outputText value="Book Name:" style="text-align:left;font-size:20px;"
                                    id="bookName"></ice:outputText>
                </ice:panelGrid>
                <ice:panelGrid>
                    <ice:inputText id="BookNameInputText" style="width: 195px;"
                                   value="#{bookBean.bookName}"></ice:inputText>
                </ice:panelGrid>
            </ice:panelGrid>
        </p>
        <br/>
        <br/>
    </ice:form>
</h:body>
</html>