• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ajax Hello World example using Servlet

 
Ranch Hand
Posts: 64
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic