Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Professional Ajax ISBN: 978-0-471-77778-6
This is the forum to discuss the Wrox book Professional Ajax by Nicholas C. Zakas, Jeremy McPeak, Joe Fawcett; ISBN: 9780471777786
Important: For the new 2nd edition of this book, please post here instead: [url="http://p2p.wrox.com/forum.asp?FORUM_ID=307"]http://p2p.wrox.com/forum.asp?FORUM_ID=307[/url]
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Ajax ISBN: 978-0-471-77778-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 23rd, 2006, 06:14 AM
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
  #2 (permalink)  
Old September 23rd, 2006, 06:52 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

So what's the problem? Does parseMessages() get called? What's the last alert message you get?

--

Joe (Microsoft MVP - XML)
  #3 (permalink)  
Old September 25th, 2006, 11:33 AM
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

hi...

Yes... parseMessages() method is called...and going upto
alert("Execution of 'response = req.responseXML.documentElement;'" );
 but showing error in line
itemDescription = response.getElementsByTagName('description')[0].firstChild.data;

Thanks &amp; Regard
Nigamananda Rout
  #4 (permalink)  
Old September 26th, 2006, 02:20 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Heaven forfend that anyone ever posts an error message...

Try navigating to 'http://localhost:8084/Aajax/getDescription.jsp?channelId=<validId>&itemId=<val idId> to make sure your XML is being returned.

Try alerting req.responseText to see if there's any content.

Post the output of responseText here and the error message if it's still failing.

You could also try using a more up to date class such as MSXML2.XmlHttp.3.0.

--

Joe (Microsoft MVP - XML)
  #5 (permalink)  
Old October 10th, 2006, 01:06 AM
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

Hi...

i tried but not getting sucess....

Can u give me a sample code of a very simple application.... to which i can run and will try to know about it...

You can mail me on nigam.anand@geetup.net



Thanks &amp; Regard
Nigamananda Rout
  #6 (permalink)  
Old October 10th, 2006, 02:28 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I refer to my previous post. I am trying to help but you failed to any of the things I asked...

--

Joe (Microsoft MVP - XML)
  #7 (permalink)  
Old January 18th, 2007, 12:19 PM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to place_bust
Default

Hi nigam,

I know what is the problem.

see when your XML is not proper (having reserved words like &, ", °, etc.)
in that case you must have to replace them with html codes.
replace & with &, " with " etc.

that may solved the problem. still you find error then that means there is having some special character in your XML String which is not suppose to be there.

Only solution I have for that is replace that character with HTML code.

Is any one know how can I completely get out of this problem



Similar Threads
Thread Thread Starter Forum Replies Last Post
[Announce] LGPL Java, XSL and Ajax based Framework erkan_cengiz XSLT 0 March 27th, 2008 10:27 AM
AJAX with JSP kaviarasu_0205 BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 March 30th, 2007 08:06 AM
Ajax with JSP jyothi BOOK: Professional Ajax ISBN: 978-0-471-77778-6 0 December 28th, 2006 09:14 PM
java and jsp harshika Apache Tomcat 1 August 6th, 2005 05:15 PM
java/jsp and MySQL harshika Java Databases 2 August 2nd, 2005 02:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.