从App Engine检索数据

时间:2014-06-16 00:06:31

标签: java google-app-engine

我是GAE的初学者,我的应用程序正在进行插入,但不是从数据库返回数据。日志中不会显示错误。 有什么问题?

关注我的工厂课程:

import javax.persistence.EntityManagerFactory;

import javax.persistence.Persistence;

public class EMFService {

    public static final EntityManagerFactory emfInstance = 
            Persistence.createEntityManagerFactory("transactions-optional");

    private EMFService(){}

    public static EntityManagerFactory get()
    {
        return emfInstance;
    }
}

关注我的Select课程:

public List<Pessoa> listPessoas()
{
    EntityManager em = EMFService.get().createEntityManager();
    List<Pessoa> lista;

    try
    {
        Query q = em.createQuery("select p from Pessoa p");
        lista = (List<Pessoa>) q.getResultList();

    }
    finally
    {
        em.close();
    }


    return lista;

}

关注我的JSP页面:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Pessoas</title>
</head>
<body>

<table border=1>
        <thead>
            <tr>
                <th>Nome</th>
                <th>Idade</th>
            </tr>
        </thead>
        <tbody>
            <c:forEach items="${pessoas}" var="pessoa">
                <tr>
                    <td><c:out value="${pessoa.nome}" /></td>
                    <td><c:out value="${pessoa.idade}" /></td>
                </tr>
            </c:forEach>
        </tbody>
    </table>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

检查数据存储区中变量的大小写与JSP页面中的变量大小写相同。也就是说,因为数据存储区中的变量"Pessoa",所以JSP页面中的变量也应该是"Pessoa" 。此外,您应该使用Firebug来调试您的应用程序。使用console.log()查看从数据存储区返回的内容。