Lukasz Lenart escribió:
Copy-paste your jsp and/or action and we will see..


Regards
I call the method getUsuarios() that should return all the idusers of the database (just created and working, tested) . This method returns an Arraylist (mostrar) which is saved in a bean session. Afterwards, the id users of this bean will be displayed in the mostrarUsuario.jsp page. As there are users in the DB, the lenght Arraylist should not be zero so the forward returned should be "success", and not "fail" . Note that the struts-config.xml has been changed from the last one, this is the good one -> mostrarUsuario action in session scope. However I obtain the same results with scope request, as described in the last mail:

--------------- This is the action MostrarUsuarioAction.java: ------------------

package com.gentaiw.struts.action;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.gentaiw.struts.form.UserLogin2Form;

public class MostrarUsuarioAction extends Action {

public ArrayList<UserLogin2Form> mostrar = new ArrayList<UserLogin2Form>(); public ActionForward mostrarUsuario(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws SQLException { HttpSession session = request.getSession(); //we create the session

       mostrar.clear();
mostrar = getUsuarios(); //we call the getUsuarios method to obtain the users of the DB
       System.out.println("NUM ITEMS USUARIO LIST -> "+mostrar.size());
       session.setAttribute("mostrarlist", mostrar);
if (mostrar.size()==0){ return mapping.findForward("fail"); }else{
           return mapping.findForward("success");
       }

   }// END MOSTRAR USUARIO
private ArrayList<UserLogin2Form> getUsuarios() throws SQLException { Connection conn = null;
       Statement stmt = null;
       ResultSet rs = null;
try { //INI try DataSource dataSource = (DataSource)servlet.getServletContext().getAttribute("usuario"); //key datasource conn = dataSource.getConnection();
           conn.setAutoCommit(true);
           String sqlConsulta = "SELECT * FROM usuario";
           rs = stmt.executeQuery(sqlConsulta);
while (rs.next()){ //INI while
               UserLogin2Form miUsuario = new UserLogin2Form();
System.out.println("USUARIO"+miUsuario.getIdusuario().toString());
               mostrar.add(miUsuario);
} //END while
           rs.close();
System.out.println("NUM ITEMS DENTRO USUARIO LIST -> "+mostrar.size());
       }//END try
finally {
               if (rs!=null){
                   try{
                       rs.close();
                   } catch (SQLException sqlEx){ //ignore }
                   rs = null;
                   }
if (stmt!=null){
                   try{
                       stmt.close();
                   } catch (SQLException sqlEx){ //ignore }
                   stmt = null;
                   }
               }
} }//END finally return mostrar;
   }
} //END


--- --------This is the JSP page mostrarUsuario.jsp : -------------

<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-bean"; prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html"; prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic"; prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles"; prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html:html lang="true">
 <head>
   <html:base />
   <title>eliminarUsuario.jsp</title>
 </head>
 <body>Lista usuarios <br>
    <logic:iterate name="mostrarlist" id="list" scope="session"><br>
<td>id usuario: <bean:write name="list" property="idusuario" /><td/><br>
   </logic:iterate>
  </body>
</html:html>


-------- Struts.config.xml ----------

   <action
     attribute="MostrarUsuarioForm"
     name="MostrarUsuarioForm"
     path="/mostrarUsuario"
     scope="session"
     type="com.gentaiw.struts.action.MostrarUsuarioAction"
     validate="false">
     <forward name="success" path="/mostrarUsuario.jsp" />
     <forward name="fail" path="/usuarioCreado.jsp" />
   </action>
--------------EOF-------------------

If you need any more info, just let me know. Thanks for your help.
Regards,


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to