带会话的基本JSF不';我不能在玻璃鱼里工作

带会话的基本JSF不';我不能在玻璃鱼里工作,jsf,session,glassfish,Jsf,Session,Glassfish,我想在集群环境中测试JSF2会话和应用程序范围bean的会话复制,目前正在尝试使用glassfish。为此,我创建了一个简单的应用程序,首先将其部署到服务器上,以验证它是否正常工作(不正常) 以下是我迄今为止所做的: 在Oracle VirtualBox中安装Ubuntu虚拟机 将glassfish作为zip文件下载,并将其解压缩到主目录中 启动玻璃鱼 将JSF应用程序部署为war文件 转到应用程序的页面:localhost:8080/jsftest/index.jsf 尝试设置保存在会话/应用

我想在集群环境中测试JSF2会话和应用程序范围bean的会话复制,目前正在尝试使用glassfish。为此,我创建了一个简单的应用程序,首先将其部署到服务器上,以验证它是否正常工作(不正常)

以下是我迄今为止所做的:

  • 在Oracle VirtualBox中安装Ubuntu虚拟机
  • 将glassfish作为zip文件下载,并将其解压缩到主目录中
  • 启动玻璃鱼
  • 将JSF应用程序部署为war文件
  • 转到应用程序的页面:localhost:8080/jsftest/index.jsf
  • 尝试设置保存在会话/应用程序范围中的变量
  • 根据web.xml中的javax.faces.STATE_SAVING_方法,结果如下:

    • 服务器:引发viewExpiredException
    • 客户端:未存储值,显示默认值
    要创建应用程序,我执行了以下操作:

  • 在eclipse中创建新的动态web项目
  • 在WEB-INF/lib中解压myfaces core中的所有文件
  • 将classes文件夹设置为WEB-INF/classes
  • 编写bean和.xhtml,如下所示
  • 会话作用域bean(应用程序作用域类似):

    index.xhtml:

    <?xml version="1.0" encoding="UTF-8"?>
    <!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:f="http://java.sun.com/jsf/core"      
      xmlns:h="http://java.sun.com/jsf/html">
    
    <h:head>
        <title>JSF 2.0 Hello World</title>
    </h:head>
    <h:body>
        <h3>JSF 2.0 Hello World Example - hello.xhtml</h3>
        <h:outputText value="Session id: #{sessionScope['id']}" />
        <h:form>
            <h:panelGroup>
                <h:outputText value="Session Variable:"/>
                <br/>
                <h:inputText value="#{sessbean.value}"/>
            </h:panelGroup>
            <h:commandButton value="submit"/>
        </h:form>
        <h:form>
            <h:panelGroup>
                <h:outputText value="Application Variable:"/>
                <br/>
                <h:inputText value="#{appbean.value}"/>
            </h:panelGroup>
            <h:commandButton value="submit"/>
        </h:form>
    </h:body>
    </html>
    
    
    JSF2.0 Hello World
    JSF2.0 Hello World示例-Hello.xhtml
    

    所以这个非常基本的例子不起作用。有什么建议吗


    另外,会话ID没有显示在#{sessionScope['ID']}中,不知道这是不是一种方法。

    通过删除(生成的)web.xml文件的一部分使其正常工作。工作文件如下所示:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
      <display-name>jsftest</display-name>
      <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
      </servlet-mapping>
    </web-app>
    
    
    JSF测试
    Facesservlet
    javax.faces.webapp.FacesServlet
    1.
    Facesservlet
    *.jsf
    
    我去掉了什么(不知道是哪个部分导致了故障):

    
    javax.servlet.jsp.jstl.fmt.localizationContext
    资源.应用
    状态保存方法:“客户端”或“服务器”(=默认值)。参见JSF规范2.5.2
    javax.faces.STATE_保存方法
    客户
    此参数告诉MyFaces是否应允许使用javascript代码
    呈现的HTML输出。
    如果允许使用javascript,则命令链接锚定将具有javascript代码
    提交相应的表格。
    如果不允许使用javascript,则保存信息和嵌套参数的状态
    将作为url参数添加。
    默认值为“true”
    org.apache.myfaces.ALLOW_JAVASCRIPT
    真的
    如果为true,则将格式化呈现的HTML代码,使其“可读”
    i、 e.将写入额外的行分隔符和空格,但不会
    影响HTML代码。
    默认值为“true”
    org.apache.myfaces.PRETTY_HTML
    真的
    org.apache.myfaces.DETECT\u JAVASCRIPT
    假的
    如果为true,则将呈现一个能够恢复
    前垂直滚动每个请求。方便的功能,如果你有网页
    对于长列表,您不希望浏览器页面总是跳转到顶部
    如果您触发的链接或按钮操作保持在同一页面上。
    默认值为“false”
    org.apache.myfaces.AUTO_滚动
    真的
    org.apache.myfaces.webapp.StartupServletContextListener
    
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
      <display-name>jsftest</display-name>
      <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
      </servlet-mapping>
    </web-app>
    
      <context-param>
        <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
        <param-value>resources.application</param-value>
      </context-param>
      <context-param>
        <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
      </context-param>
      <context-param>
        <description>
        This parameter tells MyFaces if javascript code should be allowed in
        the rendered HTML output.
        If javascript is allowed, command_link anchors will have javascript code
        that submits the corresponding form.
        If javascript is not allowed, the state saving info and nested parameters
        will be added as url parameters.
        Default is 'true'</description>
        <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
        <param-value>true</param-value>
      </context-param>
      <context-param>
        <description>
        If true, rendered HTML code will be formatted, so that it is 'human-readable'
        i.e. additional line separators and whitespace will be written, that do not
        influence the HTML code.
        Default is 'true'</description>
        <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
        <param-value>true</param-value>
      </context-param>
      <context-param>
        <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
        <param-value>false</param-value>
      </context-param>
      <context-param>
        <description>
        If true, a javascript function will be rendered that is able to restore the
        former vertical scroll on every request. Convenient feature if you have pages
        with long lists and you do not want the browser page to always jump to the top
        if you trigger a link or button action that stays on the same page.
        Default is 'false'
    </description>
        <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
        <param-value>true</param-value>
      </context-param>
      <listener>
        <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
      </listener>