๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.lenguajes.java
Article #358

problema resuelto SERVLETS + LISTENERS+ VISUALIZAR TODOS LOS USUARIOS DENTRO DEL SISTEMA

#358
From: GRUPOS DE JAVA
Date: Thu, 17 May 2007 21:22
116 lines
4976 bytes
AQUI COMPARTO ALGO QUE PARA MI ME COSTO DEDUCIR PERO REALMENTE LA
IMPLEMENTACION ESTUVO FACIL AQUI DEJO EL CODIGO POR SI ALGUIEN QUIERE
VER TODOS LOS USUARIOS QUE HAN ENTRADO A UN SISTEMA A TRAVES DE SU
IDENTIFICACION DE USUARIO, ALGO ASI COMO CUANDO ENTRA AL MSN ALGUIEN,
ESTARIA MEJOR IMPLEMENTADO SI ESTUVIERA EN JSP's PERO YO ESTUVE
TRABAJANDO CON SERVLETS ASI QUE AQUI TIENEN UN PRINCIPIO.

Validador
public class Validador extends HttpServlet {
  private PrintWriter out = null;
//listener de usuarios dentro del sistema
  private listeners.listenerDeSesionUsuarios LDSU = new
 
listeners.listenerDeSesionUsuarios();

  public void service(HttpServletRequest request, HttpServletResponse
response)
        throws ServletException, IOException, IllegalStateException {
   if (request.getMethod() == "POST") {
    try {
      this.request = request;
      this.response = response;
      validarEntrada();
    }
    catch (IOException ex) {
        System.out.println("Excepcion de E/S "+ex);
        response.sendError (404);
    }
    catch (IllegalStateException exc) {
        System.out.println("Excepcion de Sesion "+exc);
    }
   }
   else {
        System.out.println("ยกยกยกยก Metodo No Soportado !!!!");
        response.sendError (404);
   }
  }

 public void validarEntrada() throws IOException {
                 .........
                 out.print("<DIV ALIGN=\"CENTER\"><TH ALIGN=\"CENTER
\">"+
                           "<H6><p align=\"center\">Usuarios dentro "+
                           "del sistema</p>");
                 Vector elementosU = (Vector)LDSU.getUsuarios();
                 for(int i=0;i<elementosU.size();i++) {
                     out.print("<STRONG><IMG SRC="+
                     "\"../images/usuariosActivos.jpg\" "+
                     "ALIGN=CENTER></STRONG>-><EM>"+
                    (String)elementosU.elementAt(i)+"</EM><BR
CLEAR><BR></H6></DIV>");
                 }
                 ........
 }
}

------------------------------------------------------------------------------------------------------------------------------------
listenerDeSesionUsuarios.java

package listeners;

import java.io.IOException;
import java.util.Vector;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.http.HttpSession;

public class listenerDeSesionUsuarios implements
HttpSessionAttributeListener {
    private boolean debug = false;
    private static Vector Usuarios = new Vector();

    public listenerDeSesionUsuarios() {  }

    public void attributeAdded(HttpSessionBindingEvent e) {
      HttpSession session = e.getSession();
      if(e.getName()=="info") {
         Usuarios.add(e.getValue());
      }
      if (debug) {
         System.out.println("El usuario ->"+e.getValue()+" entro al
sistema el"+
                            new java.util.Date());
      }
    }

    public void attributeRemoved(HttpSessionBindingEvent e) {
      HttpSession session = e.getSession();
      if(e.getName()=="info") {
         Usuarios.remove(e.getValue());
      }
      if (debug) {
         System.out.println("El usuario ->"+e.getValue()+" salio del
sistema");
      }
    }

    public void attributeReplaced(HttpSessionBindingEvent e) {
      HttpSession session = e.getSession();
      if (debug) {
      System.out.println(" Atributo reemplazado, sesion "+session+":
"+
                      e.getName()+"="+e.getValue()+" el "+new
java.util.Date());
      }
    }

    public static Vector getUsuarios() {
        return Usuarios;
    }
}


ESPERO QUE LES SIRVA DE ALGO, PARA MI JALA, SUERTE EN SUS PROYECTOS Y
EN SUS TRABAJOS.
Technical Details
Message-ID: <1179436933.568141.193620@o5g2000hsb.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!postnews.google.com!o5g2000hsb.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 1116f3,6f821780fdfce18c,start
X-Google-Attributes: gid1116f3,public
X-Google-Language: SPANISH,ASCII
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!postnews.google.com!o5g2000hsb.googlegroups.com!not-for-mail
From: GRUPOS DE JAVA <omm1979@gmail.com>
Newsgroups: es.comp.lenguajes.java
Subject: problema resuelto SERVLETS + LISTENERS+ VISUALIZAR TODOS LOS USUARIOS DENTRO DEL SISTEMA
Date: 17 May 2007 14:22:13 -0700
Organization: http://groups.google.com
Lines: 117
Message-ID: <1179436933.568141.193620@o5g2000hsb.googlegroups.com>
NNTP-Posting-Host: 189.131.71.75
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1179436944 27303 127.0.0.1 (17 May 2007 21:22:24 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 17 May 2007 21:22:24 +0000 (UTC)
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: o5g2000hsb.googlegroups.com; posting-host=189.131.71.75;
   posting-account=SUVqDAwAAACMYIJlcEhY29h6VjIQnh1_