Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Ajax Hello World example using Servlet

 
Ranch Hand
Posts: 64
MySQL Database PHP Java
  • 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
 
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
MySQL Database PHP Java
  • 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
 
Get me the mayor's office! I need to tell him about this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!