Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 365091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:30:14+00:00 2026-05-12T13:30:14+00:00

I don’t have much experience with servlets and I’ve been going around in circles

  • 0

I don’t have much experience with servlets and I’ve been going around in circles search for an answer to my issue. So it’ time to get the experts answers! 🙂

Overview: I need to get Javascript to call my servlet and return data to update the value on a form.

I have a java servlet running in Glassfish V2.1 called DBGet, the purpose of which is to return a string of data from an mysql database. I no problems coding that part.

When I try to get javascript to access the DBGet servlet I’m getting an XML Response object back that I really don’t know how to parse to get the data. I’m not even sure if this is the best method to use. So I’m open to other solutions.

I found this code on the net. and modified it to work with what I have.

function ajaxLoad(logid) {
var servlet = "DBGet";          //the name (URI) of the sevlet
var arg = "logid=" + logid;     //attributes
var req = servlet + "?" + arg;  //compiling the request

addrequest(req);                          //calls the addrequest function
request.onreadystatechange = function(){  //this is used to listen for changes in the request's status
 if(this.readyState == 2) {
   //not sure what to do here.....
  }
 }
alert(request.toString()); //for testing 

}

function addrequest(req) {

try {                                     //create a request for netscape, mozilla, opera, etc.
    request = new XMLHttpRequest();
}catch (e) {

    try {                                 //create a request for internet explorer
        request = new ActiveXObject("Microsoft.XMLHTTP");
    }catch (e) {                           //do some error-handling
        alert("XMLHttpRequest error: " + e);
    } }

request.open("GET", req, true);       //prepare the request
request.send(null);     //send it

return request;}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T13:30:14+00:00Added an answer on May 12, 2026 at 1:30 pm

    The javascript technique you’re using to retrieve data from the server is often called Asynchronous Java And XML (AJAX). You will want to set up the onreadystatechange method in addrequest(), before calling send(); what you want to do is pass in a callback method to addrequest(), and:

    if (http.readyState == 4 && http.status == 200) {
      callback(http);
    }
    

    A request goes out when send() is called; the onreadystatechange() method is fired when the response is received from the server. This can be done synchronously (the browser will hang until the response is received) or asynchronously (the sending method exits and other code/behavior can run until the onreadystatechange() is triggered). In your callback method:

    -http.responseText has the result of the request

    -http.responseXML has a DOM-style XML document object, if the response comes in valid XML format.

    -Check the http.responseXML.parseError.errorCode (0 indicates success)

    -If there is an error, http.responseXML.parseError.reason shows the error message

    -Note that the AJAX call may be a “success” but the server may send back an error response; you should check for this, also.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 167k
  • Answers 167k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes you can. There are two ways to stream video… May 12, 2026 at 1:33 pm
  • Editorial Team
    Editorial Team added an answer Bacause shared libraries have to be linked to at runtime,… May 12, 2026 at 1:33 pm
  • Editorial Team
    Editorial Team added an answer You can check for not null like this: where e["FirstName"]… May 12, 2026 at 1:33 pm

Related Questions

In order to apply a triggered animation to all ToolTip s in my app,
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I don't know when to add to a dataset a tableadapter or a query
I don't edit CSS very often, and almost every time I need to go
I don't understand where the extra bits are coming from in this article about

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.