Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.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 使用Jmeter测试登录功能后,在范围内找不到bean userList_Java_Hibernate_Jsp_Login_Jmeter - Fatal编程技术网

Java 使用Jmeter测试登录功能后,在范围内找不到bean userList

Java 使用Jmeter测试登录功能后,在范围内找不到bean userList,java,hibernate,jsp,login,jmeter,Java,Hibernate,Jsp,Login,Jmeter,我有一个用于大学项目的web应用程序(使用Hibernate,我无法避免,因为这是考试测试的重点之一),我需要一个登录功能 在我使用Jmeter运行了一些测试(Basicali http get e post in the login)之后,我发现在20次测试之后,webapp停止工作并返回以下消息:bean userList not found in scope 基本上,我需要重新启动Mysql以使应用程序再次工作 这是登录功能的代码: <jsp:root version="2.0" x

我有一个用于大学项目的web应用程序(使用Hibernate,我无法避免,因为这是考试测试的重点之一),我需要一个登录功能

在我使用Jmeter运行了一些测试(Basicali http get e post in the login)之后,我发现在20次测试之后,webapp停止工作并返回以下消息:bean userList not found in scope 基本上,我需要重新启动Mysql以使应用程序再次工作

这是登录功能的代码:

<jsp:root version="2.0" xmlns:jsp="http://java.sun.com/JSP/Page"
 xmlns:c="urn:jsptld:http://java.sun.com/jsp/jstl/core">
 <jsp:directive.page contentType="text/html; charset=UTF-8" />
<jsp:scriptlet>
    session.setAttribute( "userList", com.ggm.hibernateConnection.DAO.getData());
</jsp:scriptlet>
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <title>Login Page</title>
 </head>
 <body background="sfondo_jsp2.jpg" text="white" link="white" vlink="yellow">
 <div align =" center">
 <br></br>
 <br></br>
 <h1> Benvenuto in Ggm Web Application! </h1>
 <br></br>
 <br></br>
 <br></br>
<jsp:useBean id="actualUser" class ="com.ggm.javaBean.LoginBean" scope="session"> </jsp:useBean>
 <form name="form1" method="POST">
 Username<input type="text" name ="loginUser"></input>
 <br></br>
 Password<input type="password" name ="loginPassword"></input>
 <br></br>
 <input type = "submit" value = "Login"></input>
 <jsp:setProperty name="actualUser" property="loginUser"></jsp:setProperty> 
 <jsp:setProperty name="actualUser" property="loginPassword"></jsp:setProperty> 
 </form>
 Non sei Registrato? Clicca <a href ="registeruser.jsp">QUI</a> per registrarti! 
 <jsp:useBean id="userList" scope="session" type="java.util.List"> </jsp:useBean>
 <c:forEach items="${userList}" var="UserTable">
 <jsp:setProperty name="actualUser" property="databaseUser" value="${UserTable.userName}"></jsp:setProperty>
 <jsp:setProperty name="actualUser" property="databasePassword" value="${UserTable.password}"></jsp:setProperty>
 <c:if test="${actualUser.login}">
  <jsp:directive.page import="javax.servlet.http.Cookie"></jsp:directive.page>
 <jsp:setProperty name ="actualUser" property ="loginUser" value ="null"></jsp:setProperty>
 <c:set var="authorization" value="${true}" scope="session" ></c:set>
 <a href = "poi.jsp">Ciao! sei loggato ora! Clicca qui per andare alla pagina di Inserimento POI</a>
 <c:redirect url="poi.jsp"></c:redirect>
 </c:if>
 </c:forEach>
 </div>
 </body>    
 </html>
 </jsp:root>

setAttribute(“userList”,com.ggm.hibernateConnection.DAO.getData());
登录页面




Ggm Web应用程序中的Benvenuto!





用户名

密码

非sei注册?Clicca per registrarti!
这是访问数据库的DAO clas(通过Hibernate)

package com.ggm.hibernateConnection;
导入org.hibernate.Session;
导入org.hibernate.SessionFactory;
导入org.hibernate.cfg.Configuration;
导入org.hibernate.*;
导入java.util.*;
公共类DAO
{
公共静态列表getData()
{
SessionFactory SessionFactory=新配置().configure().buildSessionFactory();
Session Session=sessionFactory.getCurrentSession();
列表结果=空;
尝试
{
session.beginTransaction();
Query Query=session.createQuery(“来自用户”);
结果=query.list();
session.getTransaction().commit();
query.setReadOnly(true);
query.setMaxResults(50);
session.flush();
session.close();
}
捕获(例外e)
{
e、 printStackTrace();
}
返回结果;
}
}

PS:对不起,我的学术英语很差。

不应该在每次请求时都创建会话工厂。会话工厂是针对每个应用程序的,因此只构建(配置)一次,并重用它

谢谢,我将查看代码并将解决方案粘贴到我的问题上。可能明天吧!我需要一些睡眠
package com.ggm.hibernateConnection;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.*;
import java.util.*;

public class DAO
{
    public static List<?> getData ()
    {
        SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
        Session session = sessionFactory.getCurrentSession();
        List<?> result = null;
        try
        {
            session.beginTransaction();
            Query query = session.createQuery("from Users");
            result = query.list();
            session.getTransaction().commit();
            query.setReadOnly(true);
            query.setMaxResults(50);
            session.flush();
            session.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return result;      
    }

}