Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Accessing Servlet by HTML

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi EveryBody

I have 1 Htm file start.htm with followin java script



function validateLogin() {
1.var Text1 = document.getElementById("Text1").value;
2.alert('Text1 = '+Text1);
3.var url = "http://localhost:8080/esb/AJAXUtil?Text1="+Text1;
4.xmlHttp.open("POST",url);
5.xmlHttp.onreadystatechange = callback;
6.xmlHttp.send(null);
}

function callback() {
7.alert('callback');
8.if(xmlHttp.readyState == 4) {
9.if (xmlHttp.status == 200) {
10.var response = xmlHttp.responseText;
11.alert ('response = '+response);
}
}
}

The above is the ajax implementation and work good if I rename the file to index.jsp put it to the root folder of the application.

But in my scenerio I have to put the file in somewhere else.
I get error in javascript in line 4.

Please suggest me the solution.

In other word I re explain my problem as.

I have an html page running on q-matic server. I wnat to connect to 1 of my servlet on tomcat to verify the telephone no.

Thank You
Syed Saifuddin
 
Sheriff
Posts: 67620
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
Please take the time to choose the correct forum for your posts. This forum is for questions on JSP.

This post has been moved to a more appropriate forum.
 
Bear Bibeault
Sheriff
Posts: 67620
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

But in my scenerio I have to put the file in somewhere else.

We can't help you unless you tell where that "somehwere else" is. Is it in the same web application? If so, you need to verify that the URL you are using is correct.

If not, is it from a web app on the same server?

Is it on a differrent server? If so, you'll run into trouble with the Ajax security model (which can be solved with a server-side proxy relay).

Which scenario represents your issue?
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Syed,

there's probably something in your JSP (maybe a scriptlet?)
that declares and initializes the xmlHttp variable.
And of course scriptles won't work in a html file.

Maybe you can post some of your JSP-code.

Herman
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic