Pages

Wednesday, October 21, 2015

Printing binary numbers In C

Because I am following K&R page by page, example by example I decided to document my effort here.  Sometimes I will be posting the answer to the question and sometimes like today I will be posting some code that solves a problem.

This is my code for printing numbers in binary format in C:


 #include <stdio.h>  
 int main() {  
   unsigned long long int x,mask,temp;  
   int leadingzero=1;int i;  
   mask=1;  
   printf("Enter a decimal number: ");  
   if (scanf("%llu",&x)) {  
     printf("Binary representation: ");  
     i=sizeof(x)*8;  
     mask = mask << i-1;  
     while (i) {  
       if ((mask & x ) == mask) {  
         printf("1");  
         leadingzero=0;}  
       else {  
         if (!leadingzero) { printf("0"); }  
       }  
       x=x<<1; i--;  
     }  
     printf("\n");  
   }//if scanf was ok  
 }  


The concept is the following:
  1. Create a mask that has a 1 in the MSBit of a variable of the same size of the decimal to convert. Both, the mask and the input variable,x, are unsigned int. In my machine, a x86_64, that means 4 bytes of length. So, in my case mask has a 1 in the bit number 31 and 0 in the rest of the bits.
  2. Start a while loop of 32 iterations. In every iteration execute a bitwise AND (&) between the mask and x, this one shifthed to the right one digit per iteration.  When the the MSB of the shifted version of x is one, the AND result in the same value of mask, so a 1 is printed.
  3. leadingzero is just a nice addition, in my opinion to avoid printing leading zeroes.

And that is for this exercise.

Wednesday, January 14, 2015

Avoiding timeout in SQLDeveloper or JDeveloper connected to remote Oracle Database

I am a remote DBA for my University. Because of that I have configured a VPN Tunnel from my home to the office that works pretty well much of the time. I might say that it works great much of the time. The only complaining I've had in years is when using sqldeveloper to connect to one of the Oracle databases at the school. As long as I kept working, doing queries, inserting, updating, etc, the connection was solid and fast. But if I directed my attention to something else. Like browsing, email reading, or any other activity, after a few minutes, around 10 minutes of idle time, the connection died.  Next query I tried, sqldeveloper greeted me with a connection failure error.

I asked some of the non-remote coworkers if they were having that issue but they did not. So I focus my interest in the Firewall (both end points). I modified the services (port 1521, or application layer oracle) to have much longer timeouts that the default the firewall was using. It did not work.

The solution to this problem is so simple. Just created a sqlnet.ora file on the $TNS_ADMIN directory with the statement:

sqlnet.expire_time = 1

And restart the listener.

Every one minute Oracle  will send a ACK package to my PC, and my PC will answer back with  another ACK.
This is a small sample on how it looks in tcpdump  (I am not using the standard 1521 port for the listener).

19:13:46.036181 IP bannerdb64.server.edu.rds2 > 192.168.40.162.49726: P 4221:4231(10) ack 162 win 295
19:13:46.298970 IP 192.168.40.162.49726 > bannerdb64.server.edu.rds2: . ack 4231 win 16570
19:14:46.049832 IP bannerdb64.server.edu.rds2 > 192.168.40.162.49726: P 4231:4241(10) ack 162 win 295
19:14:46.312593 IP 192.168.40.162.49726 > bannerdb64.server.edu.rds2: . ack 4241 win 16567
19:15:46.063600 IP bannerdb64.server.edu.rds2 > 192.168.40.162.49726: P 4241:4251(10) ack 162 win 295
19:15:46.326957 IP 192.168.40.162.49726 > bannerdb64.server.edu.rds2: . ack 4251 win 16565



Note: I also create an entry on my windows 7 registry for KeepAlive every 5 minutes. But it did not work until I configure the oracle listener as shown previously. Next thing I need to know is remove that entry and see if it still working.

I'll update this post with the result.

Friday, November 8, 2013

Adventuring in the Android Word



My son just got his Nexus 7 he won when I buy him a  kit kat waffer some weeks ago. He is happy, I am happy. Not only for him but also because I've wanted for some time to get me involved in the Android ecosystem and this is a perfect time for that. While he plays GTA I will try to do something with Eclipse, Android and the Nexus 7.

Because Eclipse did not see the device at first  and I had to play around for a while to make it work, I will describe what I did in a step by step fashion:

  1. Make sure that Eclipse is closed.
  2. Go to Control Panel->System->Device Manager 
  3. Device shows with a yellow circle next to it.
  4. Right click on device and install driver manually. Point the driver location to wherever you install the <Eclipse/ADT/sdk bundle folder>/extras/google/usb_driver
  5. It installs the Google driver and in my case successfully.
  6. Go to the Nexus 7 and enable USB debugging.  Unusual trick here:  go to settings, scroll down to about table and tap 7, yes 7 times on Build Number (or Kernel version, can't be sure now) it will enable the developer mode.


If at this point you issue the command "adb devices", from the command prompt, you will see a new device, but it will say it is unauthorized.

D:\Android_development\adt-bundle-windows-x86-20130917\sdk\platform-tools>adb devices
List of devices attached
049a060f        unauthorized


 In the device you will see a message asking for authorization from the PC. Click OK, and your device is ready.
 D:\Android_development\adt-bundle-windows-x86-20130917\sdk\platform-tools>adb devices
List of devices attached
049a060f        device

Now I will go back to Eclipse and see what happens. By the way I've found some tutorials from a guy named Derek Banas about Android, what an excellent instructor.  I'll try to keep a log of my progress.

Wednesday, April 18, 2012

Debuggin with sql trace

Last week one of our Pro*C programs stopped working. The mission of this program is to read data from one table and copy some columns to other table's columns. Every few months the source table is  filled with sqlldr, which is done using an OS user.
It seems that one of those times where sqlldr was run,  the locale os environment was not properly setup, and the data was entered in the table with the wrong format (ISO8859, instead of UTF-8).

Now when the pro*c was ran, it stop with the following message:
ORA-29275: partial multibyte character

WRN-ORACERR: Error occurred in file "svpceeb.pc" at line 626
WRN-ERRSTMT: Following statement was last statement parsed:
    select count(*)  ,SPRIDEN_ID  from SPRIDEN ,SPBPERS where (((((((SPRID


As you see, the error shows the last parsed instructions. My first thought? Piece of cake, I will add a printf statment to print some identification of the record been processed, so it is easy to know exactly which one failed.
 I failed miserably on my attempt to get the processed row to print. This is a ICU environment and the programs use a lot of _TM macros. I tried printing a single variable using the following statement:
  tmprintf(&tmBundle,_TMC("\n string text, {0}”),variable); where variable was one of the bind variables used by the select count clause. 
The tmprinf always caused a memory fault when I tried. I'll take a deeper look later, but as usually happens in production you don't have the luxury of time, you need to fix the problem as soon as possible. 

Having spent some time trying to make tmprintf to work, I gave up and moved to the sql trace facility.

I added the following code, just before the failing sql statement:


  EXEC SQL
        ALTER SESSION SET tracefile_identifier = 'svpceeb_debug';
    POSTORA;
    EXEC SQL
        ALTER SESSION SET sql_trace = true;
    POSTORA;
    EXEC SQL
        ALTER SESSION SET EVENTS '10046 trace name context forever, level 12';
    POSTORA;


And this one after the failing sql statement: 

 EXEC SQL
        ALTER SESSION SET sql_trace = false;
    POSTORA;

 In order to be able to trace to a file, your username must have the 'ALTER SESSION' privilege. So login into sqlplus, sqldeveloper, toad or as a user with the right privileges to issue a : GRANT ALTER SESSION TO <USERNAME>




Now go and run the Pro*C using the USERNAME you just gave the privilege just now.


While the program runs, oracle will log, bind variables, wait events and sql tracing.  It is looking at the trace file where you can get the information of what row was the last retrieved successfully from the database. 
A useful trick to review the file:  In my case there were more than 70,000 rows processed before the program aborted. That makes for a huge log file not very easy to open.  So I just get the cursor ID of the query I knew was failing. It is something like "BINDS #46953007798952:"   where 469530077798952 is the id of the CURSOR of interest.
   so I did this:    grep -A5 "BINDS #46953007798952:"  trace_file.trc  | grep "value=" 
The output of the above command is a list one column that can be easily queried using sqldeveloper and determine which row forced the program to abort.
You must be careful that us use the same query in sqldeveloper so the order is the same order you get within the trace file. I did not have to play with the execution plan but I suppose that in some situation that would be the case.
















Wednesday, March 14, 2012

PART I, writing an app with google provisioning api in Luminis

Since my first encounter with the Tomcat and javaservlets, I had learned a few things about Javascript, that I want to post in here, but not at the moment.  Today I want to describe the process of writing an application that eventually will allow the student using our Luminis system to get a new password for their brand new gmail account.
See, Luminis stores the password of the user inside the LDAP  userPassword entry. It is stored using  a SSHA algorithm, seeded SHA. This is a very good encryption scheme, I believe, but it is not compatible with the Google Directory Sync application (GDSync), not even using the latest version of it today. (I'll check later on the current version number to post it here).
So the idea of reading the ldap directory entry using the GDSync application is not available. That gives us with several different options:
Create random passwords, populate some ldap entry not in use in the Luminis LDAP and make GDSync read it and use it for the initial password of the gmail account. How to let the student know what is the new password?
  One idea, a not very secure one, is to tell them that the initial password is some combination of birth date, some digits of their SS, phone number, part of their first name of last name, etc.
Another idea, send them the new password by mail...I personally hate that idea because of the effort, time and cost of the implementation when you are dealing with thousands of students. 

And my favorite idea, let the student be the one in control of when to change the password and aware of where to receive it.
So I have a plan to implement that favorite idea. Some parts of this plan are not yet implemented, so in future posts you will find the actual implementation:

In the Luminis Login page, the student will be presented with another form to enter his current username and password. Instead of login to Luminis, I will check his/her credentials against the Lumins LDAP and if it authenticate, another html form will be displayed. This form is going to be an HTML showing the student, all the emails account that he/she has registered in the Banner Database. So the student will select to which of the emails he will receive the new temporary password of his gmail account. The submit button will then call the servlet that eventually run the Google Apps provisioning API, that will update the gmail account, and then send the student the email with the information.

Because I just started with this Google Apps API, lets talk about how to make it work in the Luminis 4x server.
   Our Luminis sever had already all the software in place. mail.jar, sevlet-api.jar, jdk (1.5), activation.jar and ant. Ant is the only one that had the incorrect version, so I had to get the latest source (1.8.3) unzip it, and export the variable ANT_HOME to point to the folder that was created by the unzip action. I don't know how to use ant anyway, and all the tests I  have done so far have been using the compiler directly and only one java source at the time. Probably that's why it took me a while to get all  necessary jar files point by the CLASSPATH variable before my first successful compilation; CalendarTest.java, which is provided by the Getting Started with the Google Data Java Client Library (code.google.com/apis/gdata/articles/java_client_lib.html). At this moment my CLASSPATH is looking ugly and like this:

$ echo $CLASSPATH
/opt/luminis/products/tomcat/tomcat-cp/common/lib/servlet-api.jar:/opt/luminis/webapps
/luminis/WEB-INF/lib/ojdbc14.jar::/opt/luminis/webapps/luminis/WEB-INF/lib/ldapjdk.jar
:./:/home/lumadmin/gdata_staging/gdata/java/lib/gdata-calendar-2.0.jar:/home/lumadmin/
gdata_staging/gdata/java/sample/util/lib/sample-util.jar:/home/lumadmin/gdata_staging/
gdata/java/deps/jsr305.jar:/home/lumadmin/gdata_staging/gdata/java/deps/google-collect
-1.0-rc1.jar:/home/lumadmin/gdata_staging/gdata/java/lib/gdata-appsforyourdomain-1.0.j
ar:/home/lumadmin/gdata_staging/gdata/java/sample/appsforyourdomain/lib/AppsForYourDom
ainClient.jar


CalendarTest.java:
import com.google.gdata.client.*;
import com.google.gdata.client.calendar.*;
import com.google.gdata.data.*;
import com.google.gdata.data.acl.*;
import com.google.gdata.data.calendar.*;
import com.google.gdata.data.extensions.*;
import com.google.gdata.util.*;

import java.net.*;
import java.io.*;

import sample.util.*; 
public class CalendarTest {

    public static void main(String[] args) {
        CalendarService myService = new CalendarService("exampleCo-exampleApp-1.0");
        myService.setUserCredentials("root@gmail.com", "pa$$word");

        URL feedUrl = new URL("http://www.google.com/calendar/feeds/default/allcalendars/full");
        CalendarFeed resultFeed = myService.getFeed(feedUrl, CalendarFeed.class);

        System.out.println("Your calendars:");
        System.out.println();

        for (int i = 0; i < resultFeed.getEntries().size(); i++) {
          CalendarEntry entry = resultFeed.getEntries().get(i);
          System.out.println("\t" + entry.getTitle().getPlainText());
        }

    }
}
The above code did not compile. I have to change it to add a try/catch block before it compiled successfully. It seems that I am not the only one because I found another person in some forum asking for that problem.


So, now the first code. This is obvious, just the first code, it is extremely raw, with no validation code, no error handling, but it does change the password of the gmail account.



import java.net.URL;
import java.util.List;
import com.google.gdata.client.appsforyourdomain.UserService;
import com.google.gdata.data.appsforyourdomain.provisioning.UserEntry;
import com.google.gdata.data.appsforyourdomain.provisioning.UserFeed;
import sample.appsforyourdomain.AppsForYourDomainClient;
 
public class changepassword {
   public void update(String username,String password){
 String domain="yourdomain"; String admin="adminaccount"; String adminpwd="adminpwd";
       try
       {
       // Create a new Apps Provisioning service
 AppsForYourDomainClient client=new AppsForYourDomainClient(admin, adminpwd,domain);
 UserEntry user = client.retrieveUser(username);
 user.getLogin().setPassword(password);
 client.updateUser(username,user);
             }
            catch(Exception e) { System.out.print(e);}
        }
   public static void main(String args[])
   {
   String user="student_username"; String passwd="student_new_password_on_gmail";
   changepassword upusr=new changepassword();
   upusr.update(user,passwd);
   }
}

The above code compiles, and it works.  There it is. Now, you have a basic class that will change the password on the gmail account. Much more to come, as I advance in the other parts of the plan.
I think that if you are also starting like me testing the waters of luminis/gmail/ java/tomcat/servlets this might be of some help.

Sunday, March 11, 2012

Kony2012 and the professional journalist



This is a digression from my favorite field, technology. Usually I don't feel so compel to broadcast my points of view about non-technical stuff. But the viral video of Kony 2012 has produced so much rage inside me that I have to speak about it.
I knew about LRA before watching the video, I knew the government had sent a group of military experts to help the Uganda's army stop LRA and their crimes. I learned about when it happened, it was 'covered' in the news at the time, last months of 2011. But, probably like many others that heard the news, I forgot about it. I did not research, I did not feel the pain of those children.
Now it comes the video. Millions of people are shaken inside, millions have cried with Jacob and for the thousands of others like him. The producer artfully touches the emotional fiber of the viewer in his attempt to involve him in his crusade. His goal, bring Joseph Kony, a Uganda's warlord to the spotlight, in the hope that public awareness might bring governments around the world to join forces capturing Kony.

That's the main idea portrayed by the video. Is the video successful ? Yes, millions now know about the atrocities committed by Kony and others of his kind.

Why I am upset? Have you seen CNN or MSNBC lately? Probably Fox News too, I can't  muster the strength to watch Fox News, sorry..., but I suppose they are having the same spin in this story. If not, please let me know. At least, CNN and MSNBC which I watch regularly, have shown several fragments discussing the video. For them, the video was well produced, but misleading. Why, because the producer said that Kony is in Uganda, he is not anymore.
CNN brought one girl who suffered on herself the evilness of Kony's army. Her point of view, is that the video is wrong because it makes Kony a celebrity, and he does not deserve to be a celebrity. She thinks that the tormented children were the ones that should be in the center of the video.
I have nothing against this girl. That's her opinion,  That video, brought her to CNN, and that video stirred  the public opinion about a subject NONE of the professional journalist of CNN, MSNBC (again I don't know about FOX), had given any important coverage so far. The journalist failed, if they ever tried, to make the public aware and outraged of what has been happening for years in Africa. But now they dare to criticize the producer of this video, an outsider, not one of us, the respectable  journalists of the big media chains.
How important is, if this Kony is or is not in Uganda right now?. How important is that the video does not give any importance to the Uganda government army?. How important is that Kony is on the run? How important is that now he is killing fewer people than before? Isn't  it much more important that the world knows now and demand an end to this criminal?

Kony is not as relevant now as he was before, granted. But where in the world were these critics  while Kony was relevant and children in Uganda were been killed, mutilated and raped for years.  They had the chance of telling the world while it was happening, but they did not. On the other hand if a random guy start playing good basketball in the NBA, (remember Linsanity?), they can't stop writing about it.
How pathetic,


Now I feel better,

Monday, February 20, 2012

A weekend with Luminis and Tomcat

PROGRAMMING A SERVLET FOR LUMINIS 4.X FOR BANNER BY A NEWBIE PROGRAMMER.

At work we are using Luminis 4.x to allow our students to login into the University Portal.  As part of the migration to Google Application for Education we need to change the students current user id to login into the portal.
In order to accomplish that, we will run a custom sql package that will generate new user ids. The user Id, used by the Luminis portal is stored inside banner inside the table GOBTPAC as GOBTPAC_EXTERNAL_USER column. As soon as the GOBTPAC table is updated, another process needs to be run to import all the changes inside Luminis Platform. In our case we are going to import a xml file with cptool.
Once that GOBTPAC, and Luminis  are updated with the new userId, the students can no longer login into the portal. We thought out two methods to overcome this situation:
  • Change GOBTPAC_EXTERNAL_USER in a cloned database and notify the students of the oncoming change, either by email, portal mail or publish it in an internal website.
  • Go ahead and changed it in Production database, and provide them a way to retrieve the new user ID right at the Luminis Login Page.
 We opted for the second alternative as the solution for our problem as a more friendly one to the students. That way they were not forced to remember anything but their old, already inactive  user Id.

I had done some small programming with PHP reading and writing LDAP fields inside Luminis. That is why my first thought when attacking this issue was to modify the login page of Luminis to include some JavaScript/AJAX procedures and call some PHP page in the background to do the job.
Right away I found a difficulty with that approach, Luminis 4.x webserver is based on Apache-Tomcat 5.5 and as far as I know it does not install PHP support by default. I could have played with integrating the Apache webserver with Tomcat, but I really did not want to spend too much time in setups and configurations that I don't think are supported by Sungard.

Never had programmed  or used Tomcat before, so I did some initial reading and  learned that I had a couple of options here. I could have enabled the CGI module of Tomcat, not a big deal, as it is only requires some comments to be removed from a configuration file (web.xml), and a Luminis restart. Then I could have programmed some perl script to read from the text file I brought from Banner with the mappings of oldusername:newusernames. 

I know that Sungardhe Banner is moving towards a more Java/Javascript/Groovy/Grails based architecture, so I thought that learning how to program a servlet inside the Luminis Tomcat will  be more productive in the long run for the university I work for. And having a long weekend with no much to do seems like a very good investment for the time.

So, I am going to modify the login page and add it another Form  where the students will be entering the old username, the same one he/she has been using so far to get into the portal (this is going to be done in a scheduled weekend, of course). That form will be served by JavaScript functions loaded with the page and that lives inside login.jsp. The JavaScript functions will call the servlet, the servlet will grep the new username from a text file and it will send it back to the browser, where another function will use that information to update the loaded page (login.html). That is the whole picture. Now onto the details:

Login into the WebServer host of Luminis, you have very important environment variable to work with:
  •  $CP_ROOT ---this is the base, where everything luminis related is installed from.
  • $CP_DOC_ROOT--this is the base for the Luminis Web Application
  • $CP_WEBINF  --this is the WEB-INF folder of the Luminis Web Application
  • $CP_WEB_ROOT--Tomcat webserver, configuration, common libraries (servlet-api.jar is found here), logs, conf. It is the regular filestructure of a Tomcat installation.
Most of the work is done in $CP_DOC_ROOT:
Here you will find two important directories:
  • site              (this one contains the login.html  page)
  • WEB-INF  (this one is the one referred by $CP_WEBINF
  • jsp/portal    (here it is the login.jsp that needs also to be edited)
 -First the servlet:
This is a java program that imports a set of classes that are used by the Servlet container (tomcat) to allow communication with the java class from the web. Maybe that is not a 100% true technical definition, but it is the way I interpret it. Please correct me if I am wrong. Thanks!
Basically you use your regular java knowledge to do what you want to do, and the program output could be fed back to the browse, how cool is that?
So, my java program will have an input variable, the old username, and one only line of output,"notfound" or the new user id. To do that, it reads the old username and search a static file that contains the mapping of usernames with the following layout:
                        oldusername:newusername

Place your java code inside $CP_WEBINF/classes  (you don't need to have the source here, but I wil compile in this same folder, you can move the source later to where you desire)
  This is a snippet of the java program, getId.java:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.InputStream;
import java.io.InputStreamReader;

public class getUserId  extends HttpServlet {
  public void doGet(HttpServletRequest  request,                HttpServletResponse response)
  throws IOException, ServletException, IOException
    {
   String argument_name = "olduserid";
   String argument_value= request.getParameter(argument_name);
   //the above line allows you to read the value of the 
   //variable sent by the browser

  <rest of the code that search for argument value inside a ext file...regular java programming>
   //Now to produce the ouput that will be read by the browser
   response.setContentType("text/plain");
   response.setCharacterEncoding("UTF-8");
   response.getWriter().write(newusername);
   }
}


Save and compile the java program:
$javac -classpath $CP_WEB_ROOT/common/lib/servlet-api.jar getId.java

The above will generate a file getId.class, and because it was compiled inside $WEB_INF/classes is already in the right place.
Now this servlet, needs to be registered in the Tomcat as a valid servlet. That is done in $CP_WEBINF/web.xml. I added this two new sections to the web.xml of the luminis webapps:

 <servlet>
        <servlet-name>getId</servlet-name>
        <servlet-class>getId</servlet-class>
    </servlet>
 <servlet-mapping>
        <servlet-name> getId </servlet-name>
        <url-pattern> /getId/* </url-pattern>
    </servlet-mapping>

And restart Luminis:  $stopcp -a && startcp  (I haven't spend time finding out how to restart the tomcat server alone to save time...I should do it and post it here when I find out)

Once that Tomcat restarts you can try your servlet without more programming.  Go to the browser and type:
https://yourserver.yourdomain/getId?olduserid=p00215350    (https or http depending on your particular case).  Here p00215350 is a valid username that exists in the text file.  You should receive the new username in a new browser page. You might also try an invalid username and you should receive a message accordingly. In my case "not found".

So,having  a working servlet already, the rest is downhill. Modify login.html and login.jsp. As said before, login.html is found inside $CP_DOC_ROOT/site.  A regular html form was added to the page:


 <form name="newuserid" action="https://yourserver.yourdomain/cp/home/login" onSubmit="getthenewID(); return false;" method="post">
UserID Actual: <input type="text" name="currentuserid" />
<input type="submit" value="Get my New ID" />
</form>


 Above there are very important names you have to be careful when modifying login.jsp. The name of the form, must be different from the forms already in the page ( cplogin and userid),  and the name of the field where the student type his/her old user id, "currentuserid". Those names will be used inside login.jsp.

Inside login.jsp (location $CP_DOC_ROOT/jsp/portal). I added the variable  at the begining of the page. I am not a javascript programmer, but I suppose that they might call that a global scope variable. That's what I want it, a variable that exists during the session and that is declared when the login.html page was loaded into the browser. So I added at the begining of the login.jsp, right after the <script language="javascript 1.1"> directive:


 var xmlhttp = new getXMLObject();       //xmlhttp holds the ajax object
Add the following two functions to  the login.jsp:

function getXMLObject()  //XML OBJECT
{
   var xmlHttp = false;
   try {
     xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
   }
   catch (e) {
     try {
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
     }
     catch (e2) {
       xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
     }
   }
   if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
     xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
   }
   return xmlHttp;  // Mandatory Statement returning the ajax object created
}

This function creates the variable xmlhttp as a XML object that it is used in our script to communicate with the servlet requesting it for the new user id (AJAX).

Add the function getthenewID(). This one is called when the students click on the button, "Get my New ID"  on the page. When called this function sends the request to the servlet getId using the GET method,which sends the variable name and value on the URL of the request (the same way we manually tried the servlet above). The function sends the request and returns, it does not wait, it just tell the browser the name of the function that will take care of the reponse from the server.
And this is the beauty of AJAX. When the servlet finishes its work (at the server side), and send its response back to the browser, the browser does not open a new page, not even refresh the current page but whoever function that handles the response will be called by the browser. In this case the function is handleServerResponse, which is listed here:


function getthenewID() {
  var newuser = ""; 
  var olduser = document.forms['newuserid'].elements['currentuserid'].value;
  if(xmlhttp) {
    xmlhttp.open("GET","https://yourserver.yourid/getId?olduserid="+olduser,true); //getId: servlet name
    xmlhttp.onreadystatechange  = handleServerResponse;
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send();
  }
}

Things to consider, the old user id value is taken from the document, that's why you have to be careful with the name of the form that was created in login.html. 
Now the handleServerResponse function:

function handleServerResponse() {                                                
var newusername="";                                                              
   if (xmlhttp.readyState == 4) {                                                
     if(xmlhttp.status == 200) {                                                 
       newusername= xmlhttp.responseText; //Update the HTML Form element         
        if (newusername == "notfound" ) {                                        
        alert("Please provide your Current Luminis ID");                         
        document.forms['newuserid'].elements['currentuseridl'].value="";         
        document.forms['newuserid'].elements['currentuserid'].focus();           
        }                                                                        
        else {                                                                   
        document.forms['userid'].elements['user'].value = newusername;           
        document.forms['cplogin'].elements['pass'].focus();                      
        }                                                                        
     }                                                                           
     else                                                                         {                                                                                
        alert("Unknown Error. Please, reload your page and try again");          
     }
   }
}

The way handleServerResponse is written, when the student enter the current user Id and hit the Get my New ID button, his/her new user id will be filled in the Luminis User ID and the focus is passed already to the password field, so there is no need to copy/paste or memorize the new userid, if the user id is invalid an alarm window pops up notifying the user.
Pretty much this is everything that was touched.  I have extensively used Google for this research and I have an immense gratitude to everybody that has posted something I ended up using or not. I have copy and paste many fragments, from many ones, Thank you very much,