Pessoal, mais uma vez venho pedir a ajuda de voces.
Estou tentando popular um combo (struts, jsp), ocorre o erro abaixo, mais adiante tem o codigo.
Erro gerado:
SEVERE: Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: Cannot find bean under name banco
at org.apache.struts.taglib.html.OptionsTag.getIterator(OptionsTag.java:377)
at org.apache.struts.taglib.html.OptionsTag.doEndTag(OptionsTag.java:188)
at org.apache.jsp.cadclientebanco2_jsp._jspx_meth_html_005foptions_005f0(cadclientebanco2_jsp.java:420)
at org.apache.jsp.cadclientebanco2_jsp._jspx_meth_html_005fselect_005f0(cadclientebanco2_jsp.java:350)
at org.apache.jsp.cadclientebanco2_jsp._jspx_meth_html_005fform_005f0(cadclientebanco2_jsp.java:214)
at org.apache.jsp.cadclientebanco2_jsp._jspx_meth_html_005fhtml_005f0(cadclientebanco2_jsp.java:132)
at org.apache.jsp.cadclientebanco2_jsp._jspService(cadclientebanco2_jsp.java:80)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
///////////////////////////
Código:
package pct_Cadastro;
public class Banco {
private int id;
private String banco;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getBanco() {
return banco;
}
public void setBanco(String banco) {
this.banco = banco;
}
}
//////
package br.com.estudo;
public class Form_CadBanco extends ActionForm{
private Banco banco = new Banco();
public Banco getBanco(){
return banco;}
}
///////
package br.com.estudo;
public class Action_Combos extends Action {
public ActionForward cmbBanco(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
System.out.println("Entrando Action -> combo banco tela cadastro.");
try {
List<pct_Cadastro.Banco> bancos;
bancos = new pct_Cadastro.DAOBanco().getLista();
request.getSession().setAttribute("banco", bancos);
} catch (SQLException e) {
e.printStackTrace();
}
return mapping.findForward("combobancotelacadastro");
}
}
///////
package pct_Cadastro;
public class DAOBanco {
private Connection connection;
public DAOBanco() throws SQLException{
this.connection = ConnectionFactory.getConnection();
}
public List<Banco> getLista() throws SQLException {
PreparedStatement busca = this.connection.prepareStatement("select * from CBANCO order by banco");
ResultSet rs = busca.executeQuery();
List<Banco> bancos = new ArrayList<Banco>();
while(rs.next()){
Banco banco = new Banco();
banco.setId(rs.getInt("id"));
banco.setBanco(rs.getString("banco"));
bancos.add(banco);
}
rs.close();
busca.close();
return bancos;
}
/////
<?xml version="1.0" encoding="ISO-8859-1" ?><form-beans>
<form-bean name="Form_CadBanco" type="br.com.estudo.Form_CadBanco"></form-bean>
</form-beans>
<action-mappings>
<action path="/novobanco" name="Form_CadBanco" type="br.com.estudo.Action_CadBanco">
<forward name="listagem1" path="/listagembanco.do"/>
<forward name="combobancotelacadastro" path="/cadclientebanco2.jsp"/>
</action>
</action-mappings>
////////
JSP - cadclientebanco2.jsp
<%@ taglib uri=“http://struts.apache.org/tags-html” prefix=“html” %>
<%@ taglib uri=“http://java.sun.com/jsp/jstl/core” prefix=“c”%>
<%@page isELIgnored =“false” %>
…
<html:select property=“banco” >
<html:option value="">Selecione</html:option>
<html:options collection=“banco” property=“id” labelProperty=“banco” />
</html:select>
/////