3 Replies Latest reply on Jul 3, 2010 1:19 AM by Trong Tran

    Ajax & JSP

    jhakeline llican Newbie

      Hi everybody

       

      I've created a portlet, this portlet  show some information, but I don't want to refresh the page. My portlet works separate to my portal, but when I add this portlet to deploy file, doesn't work, i click on the button and my page appears into div. Maybe don't understand, but I leave the code.

      welcome.jsp and welcome2.jsp are in jsp file.

          test2.png

      welcome.jsp

      <%@ page language="java" contentType="text/html; charset=UTF-8"
          pageEncoding="UTF-8"%>
      <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                                 "http://www.w3.org/TR/html4/loose.dtd">
      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
      <title>Pagina de Indice</title>
      </head>
      
      <body>
      <script>
      var ajax;
      
      function funcionCallback()
      {
          
          if( ajax.readyState == 4 )
          {
             
              if( ajax.status == 200 )
              {
                
                  document.getElementById('salida').innerHTML = "<b>"+ajax.responseText+"</b>";    
              }
          }
      }
      
      function recuperaResidencia()
      {    
          var text = document.getElementById('entrada');
          
         
          if( window.XMLHttpRequest ){
              ajax = new XMLHttpRequest(); 
              
          }else{
              ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
             
          }
          
          ajax.onreadystatechange = funcionCallback;
      
         
          ajax.open( "GET", "welcome2.jsp?persona="+text.value, true );
          ajax.send( "" );
      }
      </script>
      
      <input type="text" id="entrada" size="77"/>
      <input type="button" value="Consultar" onclick="recuperaResidencia()"/>
      
      Lugar de residencia: <div id="salida"></div>
      
      </body>
      </html>
      
      

       

      welcome2.jsp

       

      <%
            String persona = request.getParameter("persona");
           if(persona==null){
          out.print("Nulo");
      }
      
          else if( persona.equalsIgnoreCase("jhaky") )
          {
              out.print("peru");
          }
          else
          {
              out.print("PERSONA DESCONOCIDA");
          }
      %>
      

       

      My portlet works out my portal

      test1.png

      My portlet doesn't work into the portal and appears into a div

       

      test4.png

       

       

      i hope you help me

       

      If anybody knows another way to show information without refresh all the page, please let me know

       

      thanks