• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ajax Hello World example using Servlet

 
Ravi Sree
Ranch Hand
Posts: 64
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I tried a simple AJAX example I found on net.

Here are the files:

ajax.js


com.ajax.HelloWorld.java


index.jsp


web.xml


directory structure is:-
Ravi Sree wrote:
index.jsp
ajax.js
/src
|
com/ajax/HelloWorld.java
/WEB-INF
|
web.xml
/lib
/classes
|
com/ajax/HelloWorld.class


It is not working as expected, rather i unable to see any change.
On the click of the button in the bottom-left side of IE, an error message is displayed:-


Line : 10
Char : 1
Error: Object expected
Code : 0
URL: http://localhost:8080/AjaxHW/


I am using WinXP SP2, Jdk 1.6, Tomcat 5 and IE 7 for now.
I unable to figure out if I am missing something.
I will appreciate your opinions on this.

Regards,
Sree
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why did you put your directory structure in a quote instead of code tags that would preserve its formatting?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd suggest trying it with IE8 or Firefox with Firebug, which will give you better script debugging.
 
Ravi Sree
Ranch Hand
Posts: 64
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks Bear,
I did as you suggested and found that the error was mine.
Following where the changes that I did :-

1. Remove the <script> tags in ajax.js
2. Replace with xmlHttpRequest.setRequestHeader for xmlHttpRequest.setRequestHandler in ajax.js.
One of the major typo mistakes i did
3. I wrote to call doPost inside the same resulting a unwanted recurring loop, I meant to call the doPost from doGet.
4. Change the script type from text/javascript to javascript/text in index.jsp (I dont think it is much of a change though).

Thanks again, JavaRanch rocks

Regards,
Sree
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic