View Single Post
 
Old September 23rd, 2006, 06:14 AM
nigam.anand nigam.anand is offline
Registered User
 
Join Date: Apr 2006
Location: BBSR, ORISSA, India.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to nigam.anand
Default Ajax + Java (Jsp)

Hi Dear all.......

    i am new to ajax. I am doing an application in ajax + jsp. In my client side i have
       a html file called Ajax_Client.html
     and one jsp file getDescription.jsp.

I am giving the content of two files...



Ajax_Client.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
 <head>
 <title> 1st Ajax Application</title>
 <script >
function getDescription(channelId,itemId)
{
 var url = 'http://localhost:8084/Aajax/getDescription.jsp?channelId=' + channelId + '&itemId=' + itemId;
 if (window.XMLHttpRequest)
 {
  req = new XMLHttpRequest();
 }
 else if (window.ActiveXObject)
 {
  req = new ActiveXObject("Microsoft.XMLHTTP");
 }
 req.onreadystatechange = processRequest;
 req.open("GET", url, true);
 req.send(null);

}

function processRequest() {

    if (req.readyState == 4) {
       alert ( "Hyee Nigam.... req.readyState="+req.readyState+" And req.status="+req.status+" is Comming form the Server" );
        if (req.status == 200) {

           parseMessages();

        } else {
          alert ( "Hyee Nigam.... Not able to retrieve description" ); }
      }
}

function parseMessages() {
        alert ( "Enter to the parseMessages() function" ); //--Just to print only, to check upto which line function is executing
    response = req.responseXML.documentElement;
        alert ( "Execution of 'response = req.responseXML.documentElement;' " ); //--Just to print only, to check upto which line function is executing
    itemDescription = response.getElementsByTagName('description')[0].firstChild.data;
        alert ( "Execution of 'itemDescription = response.getElementsByTagName('description')[0].firstChild.data;' " ); //--Just to print only, to check upto which line function is executing
    alert ( itemDescription ); //-- To show the content from the server
        alert ( "Execution Completed" );
}
</script>
  </head>
  <body>
  <a href="/" onmouseover="getDescription(3,1)">My 1st Ajax Application<a>
  </body>
</html>




getDescription.jsp

<html>
<body>
<%

String channelId = request.getParameter("channelId");
String itemId = request.getParameter("itemId");
//String description = new Channel(channelId).getItemDescription(itemId);
String description = "This is the description for the channelId: " + channelId + "and itemId: " + itemId;

if (description != null) {
   response.setContentType("text/xml");
   response.setHeader("Cache-Control", "no-cache");
   response.getWriter().write("<description>" + description.toString() + "</description>");
} else {
   //nothing to show
   response.setStatus(HttpServletResponse.SC_NO_CONTE NT);
}
%>

</body>
</html>




i think its problem in the function parseMessages() in Ajax_Client.html page




Thanks

Thanks &amp; Regard
Nigamananda Rout