异常捕获问题!!!
目的是通过在JSP中调用ListUser.java中的list方法实现下拉列表的值,是动态的从数据库中读出来的!
ListUser.java文件:
package ems.service;
import org.hibernate.Session;
import org.hibernate.Transaction;
import ems.hibernate.HibernateUtil;
import org.hibernate.Query;
import java.util.List;
import ems.hibernate.Usertable;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspWriter;
import
org.hibernate.HibernateException;
public class ListUser {
public void list(HttpServletRequest request, JspWriter out)
throws Exception
{
HibernateUtil hibera=new HibernateUtil();
Session session=hibera.currentSession();
Transaction tx=session.beginTransaction();
String sql= "from Usertable ";
Query query = session.createQuery(sql);
List list=query.list();
for(Iterator it=list.iterator();it.hasNext();){
Usertable user=(Usertable)it.next();
out.print( " <html:option value= ' "+user.getName()+ " '> "+user.getName()+ " </html:option> ");
}
tx.commit();
hibera.currentSession();
}
}
在JSP页面上!
<html:select property= "uname ">
<%
ListUser listuser=new ListUser();
listuser.list(request,out);
%>
</html:select>
在listuser.list(request,out)处总提示unreported exception
java.lang.Exception; must be caught or declared to be thrown不知道怎么解决,等待高手指点!!!
------解决方案--------