我正在尝试在Google App Engine上使用JSF,但是在使用Sessionscoped bean时遇到了一些麻烦。我有一个注释为@Sessionscoped的类,只有一个页面,表单中只有一个下一个按钮。当我在Eclipse中单击此按钮时,currentNumber的值每次都会更新,这正是我所期望的。但是当它部署在App Engine上时,每个请求都会将数字重置为0,因此它会越过1.无论我做什么,我似乎都无法获得会话行为,它总是表现为请求编码。它在本地工作正常,但在部署时则不行。任何人的想法?
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name = "controller")
@SessionScoped
public class Controller implements Serializable {
private int currentNumber;
public Controller() {
}
public int getCurrentNumber() {
return currentNumber;
}
public void setCurrentNumber(int currentNumber) {
this.currentNumber = currentNumber;
}
public void next() {
currentNumber++;
}
}
在appengine.xml中:
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<version>1</version>
<!-- Allows App Engine to send multiple requests to one instance in parallel: -->
<threadsafe>true</threadsafe>
<!-- Configure java.util.logging -->
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties" />
</system-properties>
<sessions-enabled>true</sessions-enabled>
</appengine-web-app>
最后是web.xml:
<?xml version="1.0" encoding="utf-8" standalone="no"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- ***** Designate client-side state saving. ***** -->
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<!-- Set the default suffix for JSF pages to .xhtml -->
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<!-- Disable use of threading for single-threaded environments such as
the Google AppEngine. -->
<context-param>
<param-name>com.sun.faces.enableThreading</param-name>
<param-value>false</param-value>
</context-param>
<!-- ***** Specify JBoss Expression Language Over Default -->
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>
<!-- ***** Load the JavaServer Faces Servlet ***** -->
<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>/faces/*</url-pattern>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<!-- ***** Specify session timeout of thirty (30) minutes. ***** -->
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value/>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>
</web-app>
更新:
将mykongs教程中提到的jsf实现更改为Mojarra的2.0.3版本神秘地完成了这一操作。如果有人知道为什么会这样,我很想知道,因为我没有在任何地方看到它。