无法在选择选项中显示数据库数据,无法为JSP错误编译类

时间:2016-12-15 15:48:19

标签: jsp

我尝试在select选项中显示数据库中的数据,但是我得到“HTTP状态500 - 无法为JSP编译类:”错误,我已经为您提供了以下代码。请帮我解决问题。

HibernateConnector。的java

public List<CountrySize> getCountriesList() {
    Configuration conf = new Configuration().configure();
    conf.configure("hibernate.cfg.xml");
    StandardServiceRegistryBuilder build = new StandardServiceRegistryBuilder().applySettings(conf.getProperties());
    SessionFactory factory = conf.buildSessionFactory(build.build());
    Session session = factory.openSession();
    Transaction tx=null;    
    CountryResults results=null;
    List<CountrySize> countries = new ArrayList<>();
    try {
        tx=session.beginTransaction();
        countries = session.createCriteria(CountrySize.class).list();
    } catch(HibernateException ex) {
        System.out.println("Error occured");
    } finally {
        session.close();
    }
    return countries;
}

testdb.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ page import= "com.countrysize.entities.CountrySize"  %>
    <%@ page import= "com.countrysize.action.HibernateConnector" %>
    <%@ page import= "java.util.*" %>
<!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>Insert title here</title>
</head>
<body>
<%! List<CountrySize> res = new ArrayList<>(); %>
<%
  HibernateConnector hc = new HibernateConnector();
res = hc.getCountriesList();

%>

<h1> Drop down box or select element</h1>
    <select>
    <%  for(CountrySize country: res){ %>
        <option value=<%= country.getCountryName()%>><%= country.getCountryName()%></option>
    <% } %>
    </select>
</body>
</html>

0 个答案:

没有答案