dropdownlistjsp+;EJB+;Servlet Java
我有一个proyect JSP EJB Servlet,然后我必须将SQL表dropdownlistjsp+;EJB+;Servlet Java,java,jsp,servlets,Java,Jsp,Servlets,我有一个proyect JSP EJB Servlet,然后我必须将SQL表city中的数据填充到dropdownlist中index.JSP。这是我在index.jsp中的代码,但是,我无法将城市插入到我的项目中 拜托,你能帮我吗 <select name="ciudad"> <option>Selecciona ciudad...</option> <c:
city
中的数据填充到dropdownlist中index.JSP
。这是我在index.jsp
中的代码,但是,我无法将城市插入到我的项目中
拜托,你能帮我吗
<select name="ciudad">
<option>Selecciona ciudad...</option>
<c:forEach items="${ciudades}" var="ciudad" >
<option>
${ciudad.idCiudad}
</option>
</c:forEach>
</select><br/>
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
List<Ciudad> ciudad = new ArrayList<Ciudad>();
try {
ciudad = CiudadService.findAll();
} catch (ServicioException ex) {
System.out.println("Error!");
Logger.getLogger(CiudadListController.class.getName()).log(Level.SEVERE, null, ex);
}
request.setAttribute("ciudades", ciudad );
getServletContext().getRequestDispatcher("/listadoCiudades.jsp").forward(request, response);
}
城市选择。。。
${ciudad.idCiudad}
受保护的void doGet(HttpServletRequest请求、HttpServletResponse响应)
抛出ServletException、IOException{
List ciudad=new ArrayList();
试一试{
ciudad=CiudadService.findAll();
}捕获(服务异常){
System.out.println(“错误!”);
Logger.getLogger(CiudadListController.class.getName()).log(Level.SEVERE,null,ex);
}
setAttribute(“ciudades”,ciudad);
getServletContext().getRequestDispatcher(“/listadoCiudades.jsp”).forward(请求,响应);
}
我正在使用Glashfish的泳池连接
这是我从postationService.java获得的findAll方法
public List<Postulante> findAll() throws ServicioException{
List<Postulante> list = null;
try{
list = em.
createNamedQuery("Postulante.findAll",Postulante.class).getResultList();
} catch (NoResultException ex) {
throw new ServicioException("No existen resultados");
}
return list;
}
public List findAll()引发服务异常{
List=null;
试一试{
列表=em。
createNamedQuery(“posturante.findAll”,posturante.class).getResultList();
}捕获(noresultex异常){
抛出新的服务异常(“不存在结果”);
}
退货清单;
}
你确定你的CiuddService.findAll()返回非空列表吗?
这是我在CiuddService.findAll()公共列表中的代码findAll()抛出服务异常{list list list list list list=null;try{list=em.createNamedQuery(“posturante.findAll”,posturante.class).getResultList();}catch(NoResultException ex){throw new ServicioException(“No existen resultados”);}返回列表;}最好将代码放在原始问题中。您没有回答我的:)我不确定我的方法findAll()是否返回非空列表。很抱歉,我的英语不是很好:(@BalusC,我不是网络开发者,我只是想学习编程,我有一个问题想问。我想你可能更友好了一点,或者帮了一点忙。最后,我在别处解决了这个问题。非常感谢那些花时间阅读这篇文章的人。