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>