Thread View: es.comp.lenguajes.java
1 messages
1 total messages
Started by GRUPOS DE JAVA
Thu, 17 May 2007 21:22
problema resuelto SERVLETS + LISTENERS+ VISUALIZAR TODOS LOS USUARIOS DENTRO DEL SISTEMA
Author: GRUPOS DE JAVA
Date: Thu, 17 May 2007 21:22
Date: Thu, 17 May 2007 21:22
116 lines
4976 bytes
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.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads