Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Gae+;Struts2+;Spring3&x2B;冬眠4+;localhost中的MySQL不';t创建http会话,并且数据存储始终为空_Java_Mysql_Hibernate_Google App Engine_Esapi - Fatal编程技术网

Java Gae+;Struts2+;Spring3&x2B;冬眠4+;localhost中的MySQL不';t创建http会话,并且数据存储始终为空

Java Gae+;Struts2+;Spring3&x2B;冬眠4+;localhost中的MySQL不';t创建http会话,并且数据存储始终为空,java,mysql,hibernate,google-app-engine,esapi,Java,Mysql,Hibernate,Google App Engine,Esapi,我在数据存储和hibernate方面遇到了问题,我已经能够在localhost中集成Gae+Struts2+Spring3+Hibernate4+MySQL,并且一切似乎都正常,但是当我尝试在HTTP中创建会话时,会话没有被创建或会话。getLastAccessedTime()始终是1970-01-01(默认值)。当我转到http:localhost:8080/_ah/admin中的数据存储链接时,没有创建会话 我使用ESAPI进行安全性和此方法: public boolean isSessio

我在数据存储和hibernate方面遇到了问题,我已经能够在localhost中集成Gae+Struts2+Spring3+Hibernate4+MySQL,并且一切似乎都正常,但是当我尝试在HTTP中创建会话时,会话没有被创建或会话。getLastAccessedTime()始终是1970-01-01(默认值)。当我转到http:localhost:8080/_ah/admin中的数据存储链接时,没有创建会话

我使用ESAPI进行安全性和此方法:

public boolean isSessionTimeout() {
    HttpSession session = ESAPI.httpUtilities().getCurrentRequest().getSession(false);
    if (session == null)
        return true;
    Date deadline = new Date(session.getLastAccessedTime() + IDLE_TIMEOUT_LENGTH);
    Date now = new Date();
    return now.after(deadline);
}
返回总是真的

我已经在appengine-web.xml中启用了会话,我不理解这个问题,只要这种配置在tomcat中有效,但在appengine 1.9.2版中就存在某种问题

我在maven中构建项目,如下所示:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <version>2.5.1</version>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <archiveClasses>true</archiveClasses>
                <webResources>
                    <!-- in order to interpolate version from pom into appengine-web.xml -->
                    <resource>
                        <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                        <filtering>true</filtering>
                        <targetPath>WEB-INF</targetPath>
                    </resource>
                </webResources>
            </configuration>
        </plugin>

        <plugin>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-maven-plugin</artifactId>
            <version>${appengine.app.version}</version>
            <configuration>
                <jvmFlags>
                    <jvmFlag>-Dappengine.generated.dir=${project.basedir}/appengine</jvmFlag>
                    <jvmFlag>-Ddatastore.backing_store=${project.basedir}/local_db.bin</jvmFlag>
                </jvmFlags>
            </configuration>
        </plugin>

    </plugins>
</build>
    public boolean isSessionTimeout() {
    HttpSession session = ESAPI.httpUtilities().getCurrentRequest().getSession(false);
    if (session == null)
        return true;
    long lastAccessedTime=System.currentTimeMillis();
    if(session.getLastAccessedTime()!=0){
        lastAccessedTime=session.getLastAccessedTime();
    } 
    Date deadline = new Date(lastAccessedTime + IDLE_TIMEOUT_LENGTH);
    Date now = new Date();      
    return now.after(deadline);
}

最后,我发现问题出在某种程度上,会话是使用默认会话创建的。getLastAccessedTime()=0,我使用当前时间设置此值,如下所示:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <version>2.5.1</version>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <archiveClasses>true</archiveClasses>
                <webResources>
                    <!-- in order to interpolate version from pom into appengine-web.xml -->
                    <resource>
                        <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                        <filtering>true</filtering>
                        <targetPath>WEB-INF</targetPath>
                    </resource>
                </webResources>
            </configuration>
        </plugin>

        <plugin>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-maven-plugin</artifactId>
            <version>${appengine.app.version}</version>
            <configuration>
                <jvmFlags>
                    <jvmFlag>-Dappengine.generated.dir=${project.basedir}/appengine</jvmFlag>
                    <jvmFlag>-Ddatastore.backing_store=${project.basedir}/local_db.bin</jvmFlag>
                </jvmFlags>
            </configuration>
        </plugin>

    </plugins>
</build>
    public boolean isSessionTimeout() {
    HttpSession session = ESAPI.httpUtilities().getCurrentRequest().getSession(false);
    if (session == null)
        return true;
    long lastAccessedTime=System.currentTimeMillis();
    if(session.getLastAccessedTime()!=0){
        lastAccessedTime=session.getLastAccessedTime();
    } 
    Date deadline = new Date(lastAccessedTime + IDLE_TIMEOUT_LENGTH);
    Date now = new Date();      
    return now.after(deadline);
}

最后,现在一切都正常了,我可以在本地创建会话,我还没有在生产中尝试过。

我需要实现自定义登录,但由于一些未知原因,我不能使用http会话,因为我的本地数据存储中没有创建AHU会话。有没有关于如何在Appengine中使用java会话的示例?我一直在搜索,但没有结果……它总是返回
null
这一事实告诉我,您尚未将app engine配置为与ESAPI集成。例如,在我集成了ESAPI的遗留应用程序中,我必须在log4j.properties中设置一个指向ESAPI日志实现的工厂设置。。。您是否完全实现了ESAPI的Authenticator设置,或者只是将ESAPI添加到遗留应用程序中?DefaultHttpUtilities类上的Javadoc说:`*通常,这是通过调用Authenticator.login()方法来完成的,该方法*自动调用setCurrentHTTP()。但是,如果要在另一个应用程序中使用这些方法*,则应在自己的代码中显式调用setCurrentHTTP()。在任何一种情况下,在重用线程之前,都必须调用ESAPI.clearCurrent()来清除threadlocal*变量。到处都有标识*的优点大于这种方法的缺点。`根据该文档判断,您要么有一个带有验证器配置的配置,要么没有显式设置请求,因此为什么它总是返回
null
如果您已经完全解决了问题,请将您的答案标记为“已接受”,这样我们就可以放弃“未回答的问题”队列。