我有一个网络应用程序(使用Hibernate,我无法避免,因为这是考试测试的重点之一)我需要一个登录功能的大学项目。
我用Jmeter运行一些测试后(在登录时使用basicaly http get e post)我发现在20次测试后,webapp停止工作,返回此消息:bean userList未在范围内找到 Basicaly我需要重新启动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>
这是访问数据库的DAO clas(通过Hibernate)
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;
}
}
PS:对不起我学习不好的英语。