Tema: como puedo
Ver Mensaje Individual
  #5 (permalink)  
Antiguo 26/05/2008, 13:14
tortuguina
 
Fecha de Ingreso: septiembre-2007
Mensajes: 9
Antigüedad: 17 años, 6 meses
Puntos: 0
Respuesta: como puedo

Hola,

Te cuento. Tengo la clase contadorAction con el metodo execute

Código:
 public String execute() throws Exception {
		    	
    ServletContext  contexto = request.getSession().getServletContext();

          synchronized (contexto) {
               Integer cont = (Integer)contexto.getAttribute("contador");
	// * Comprobamos si existe un contador 
               
                if (cont == null) {
                    cont = new Integer(0);
                    System.out.println("[ContadorVisitas]: Creamos el contador"
		                            + " de visitas");
		                }
               // * Guardamos el numero de visitas en el contexto

	int c=new Integer(cont.intValue() + 1); 
	 System.out.println("c= " +c);
	 contexto.setAttribute("contador",c);
	  		      
	        return SUCCESS;
		    }
Y luego tengo contador.jsp

Código:
<s:action name="contador">


<%
String variable = (String)request.getAttribute("contador");
%>
<%=variable%> visitas

</s:action>