【发布时间】:2015-09-27 16:24:33
【问题描述】:
我正在使用 hibernate 框架开发一个 Web 应用程序。我正在使用 JSP 进行查看。我需要将数据库表中的特定数据加载到组合框中。 在这种情况下,我需要将 ROLE 表中的所有角色 ID 加载到组合框 我的代码如下。
<tr>
<th align="left"> Role ID </th>
<td>
<!-- Combobox to get role id's -->
<%
try {
SessionFactory sf = HibernateUtil.getSessionFactory();
Session s = sf.openSession();
Transaction tx = s.beginTransaction();
Role se = new Role();
String hql = "select ROLEID from EAD.ROLE";
Query q = s.createQuery(hql);
ArrayList li = (ArrayList) q.list();
Iterator ie = li.iterator();
int size = li.size();
%>
<select>
<%
while (ie.hasNext()) {
Integer un = se.getRoleid();
%>
<option value="<%= un%>"><%= un%></option>
<%
}
%>
</select>
<%
} catch (HibernateException he) {
he.printStackTrace();
}%>
<!-- end of combobox-->
</td>
</tr>
角色.java
public class Role implements java.io.Serializable {
private int roleid;
private String title;
private String rolename;
public Role() {
}
public Role(int roleid, String title, String rolename) {
this.roleid = roleid;
this.title = title;
this.rolename = rolename;
}
public int getRoleid() {
return this.roleid;
}
public void setRoleid(int roleid) {
this.roleid = roleid;
}
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
public String getRoleName() {
return this.rolename;
}
public void setRoleName(String rolename) {
this.rolename = rolename;
}
}
我的问题是即使组合框没有显示在页面中。有什么办法解决这个问题吗??如果可以,请尽快提出解决方案。谢谢:)
【问题讨论】:
-
能否格式化源代码。 IDE 使用的是什么?
-
我正在使用 netbeans IDE
-
如果列表大小为 0,则检查 ArrayList 大小,然后没有为选择选项设置值。如果在
-
在netbeans中选择代码,按Ctrl+Shift+F格式化代码。然后编辑帖子替换编辑的代码。
-
另外,您是否在控制台中收到错误消息?