JSP+Servlet+Beans �Heeeeeelp!
843854Apr 28 2004 — edited Apr 28 2004I'm trying to implement MVC in my WebApp, but my search page is not working correctly. The situation is this: My search form ("buscar.jsp") send a value to be searched (varible called "value") to my Servlet ("QueryServlet"), this servlet send the requested value to the class called: "QueriesManager", this class connect itself to the DataBase using JDBC and execute the query. Apparently no problem.
The problem results when it return the ResultSet to QueryServlet, i'm Trying to put each row reached into a bean and storing to an interface Collection as an ArrayList Class, but this ArrayList only save since the second row and then only the last record reached is saved. The size of the Array increase normally, buy only with one same value, the last record.
�How i can solve it? I wish my ArrayList contains beans with all the result reached after the query to the DataBase.
I show the QueryServlet's POST method, where happens the problem.
----------------------------------------------------------------------------------------------------------------------------
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try{ //get data from ResultSet and set ResultBean.
QueriesManager qm = new QueriesManager();
ResultSet rs = qm.obtenerBuscar(request.getParameter("valor"),Integer.parseInt(request.getParameter("Criterio")),request.getParameter("stat"),request.getParameter("ubicFis"));
Collection beanList = new ArrayList();
ResultBean rb = new ResultBean();
while(rs.next()){
rb.setDni(rs.getString("id"));
rb.setNomCmpl(rs.getString("name"));
rb.setCod_stat(rs.getString("stat_id"));
rb.setStatus(rs.getString("stat"));
rb.setUbic(rs.getString("dept"));
beanList.add(rb);
}
ResultBean list = new ResultBean();
list.setBeanList(beanList);
//Store resultbean into request.
request.setAttribute("resultBean",list);
}
catch(SQLException se){
System.out.println("Error al manipular el ResultBean, "+se);
}
try{
//forward request to JSP for display.
getServletConfig().getServletContext().getRequestDispatcher("/resultado_busca.jsp").forward(request, response);
}
catch(IOException io){
System.out.println("Error al redireccionar el resultado, "+io);
}
}
-----------------------------------------------------------------------------------------------------------
i will be glad if u can help me...
Darkhammer.