Foros del Web » Programación para mayores de 30 ;) » Java »

Struts + Ajax

Estas en el tema de Struts + Ajax en el foro de Java en Foros del Web. Hola tengo un jsp : <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> <script type="text/javascript"> function ver(){ obj=new XMLHttpRequest(); obj.open("GET","Bienvenida.do",true); obj.onreadystatechange=mostrardatos; obj.send(null); } function mostrardatos(){ ...
  #1 (permalink)  
Antiguo 30/12/2010, 04:09
 
Fecha de Ingreso: diciembre-2010
Mensajes: 459
Antigüedad: 13 años, 4 meses
Puntos: 21
Struts + Ajax

Hola tengo un jsp :

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script type="text/javascript">
function ver(){
obj=new XMLHttpRequest();
obj.open("GET","Bienvenida.do",true);
obj.onreadystatechange=mostrardatos;
obj.send(null);
}

function mostrardatos(){
if(obj.readyState==4){
if(obj.status==200){
document.getElementById("mostrar").innerHTML=obj.r esponseText;
}
}
}

function anadir(id){
obj=new XMLHttpRequest();
obj.open("GET","Carrito.do?id="+id,true);
obj.onreadystatechange=mostrardatos2;
obj.send(null);
}

function mostrardatos2(){
if(obj.readyState==4){
if(obj.status==200){
document.getElementById("compra").innerHTML=obj.re sponseText;
}
}
}
</script>
</head>
<body onload="ver()">
<h1>Hello World!</h1>
<div id="mostrar">

</div>
<br><br><br>
<div id="compra">

</div>
</body>
</html>

y tengo un jsp que es añadido mediante ajax


<table>
<tr>
<td>Nombre</td>
<td>Categoría</td>
<td>Descripción</td>
<td>Precio</td>
<td>Imagen</td>
<td>Id</td>
</tr>
<c:forEach var="p" items="${productos}">
<tr>
<td>
${p.nombre}
</td>
<td>
${p.categoria}
</td>
<td>
${p.descripcion}
</td>
<td>
${p.precio}
</td>
<td>
<IMG SRC="${p.imagen}">
</td>
<td>
<input type="button" id="id" name="id" value="${p.id}" onclick="anadir(${p.id})">
</td>

</tr>
</c:forEach>
</table>


y me añade una listado de productos y cuando le doy al boton en un div me añade el producto pero si le vuelvoa dar a otro boton el producto anterior se borra y aparece el nuevo, como puedo hacer para que se mantenga, la funciona llama a un action q es el siguiente

public class CarritoAction extends org.apache.struts.action.Action {

/* forward name="success" path="" */
private static final String SUCCESS = "carrito";


@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
int x=Integer.parseInt(request.getParameter("id"));
System.out.println("pasa"+x);
Context ctx=new InitialContext();
OperacionesLocal operaciones=(OperacionesLocal) ctx.lookup("java:comp/env/carritobean");
//asi recuperamos el ejb
HttpSession ses=request.getSession();
ses.setAttribute("carrito", operaciones.getCarrito(x));


return mapping.findForward(SUCCESS);
}
}

Gracias por vuestra ayuda
  #2 (permalink)  
Antiguo 05/01/2011, 09:52
 
Fecha de Ingreso: diciembre-2010
Mensajes: 459
Antigüedad: 13 años, 4 meses
Puntos: 21
Respuesta: Struts + Ajax

alguien que me pueda ayudar pelase? :(

Etiquetas: ajax, struts
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:24.