populate a dropdown from a database

found below is my java, js, and html can you tell me if I am configured correctly
package com.testajax;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;

import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

import java.sql.*;

public
    class CountryServlet4 extends HttpServlet {
	
	public void doGet (HttpServletRequest req, HttpServletResponse res)
	    throws ServletException, IOException {
	    res.setContentType("text/html");
	    
	    ServletOutputStream out = res.getOutputStream();
	    out.println("<html>");
	    out.println("<head><title>Hello World</title></head>");
	    out.println("<body>");
	    
	    try {
		// The newInstance() call is a work around for some
		// broken Java implementations
	        out.println("asdf");
	        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
	    }
	    catch (Exception E) {
		out.println("Unable to load driver.");
		E.printStackTrace();
	    }
	    
	    out.println("<br><hr>");
	    
	    try {
		Connection Conn = 
		    DriverManager.getConnection("hidden","hidden","hidden");
	        
		// Do something with the Connection
		Statement Stmt = Conn.createStatement();
		ResultSet RS = Stmt.executeQuery("SELECT * from ORG_TAB");
		
		while (RS.next()) {
		    out.println(RS.getString(1));
		}
		// Clean up after ourselves
		RS.close();
		Stmt.close();
		Conn.close();
		
	    }
	    catch (SQLException E) {
		out.println("SQLException: " + E.getMessage());
		out.println("SQLState:     " + E.getSQLState());
		out.println("VendorError:  " + E.getErrorCode());
	    }
	    
	    out.println("<h1>Hello World. Sun... 1.4</h1>");
	    out.println("</body></html>");
	}
	
	public String getServletInfo() {
	  return "Create a page that says <i>Hello World</i> and send it back";
	}
    }



var req; 
  function showCustomer(str){ 
  alert("String that is passed in is :::"+str);
	   
   
	var url="T/4?countryId="+str; 
	alert("URL Referenced IS :::"+url);
    
    if (window.XMLHttpRequest){ 
		//alert("111");
      req = new XMLHttpRequest(); 
    } 
    else if (window.ActiveXObject){ 
				//alert("222");
      req = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 

    req.open("Get",url,true); 

alert("Faith is a geek ");
    req.onreadystatechange = callback; 
    req.send(null);
  } 

  function callback(){ 
//alert("In Call Back Function aaa" +req.status+"\n"+req.readyState);
    if (req.readyState==4){ 
      if (req.status == 200){
    //  alert("In Call Back Function bbb" +req.status+"\n"+req.readyState);
  //document.companydd.value="a"; //Update the HTML Form element 
  //document.getElementById('New_NAME').value='b'
 //  document.getElementById('New_NAME').value='b'

      	//var xmlText=req.responseText;
      	//alert(xmlText).value
        //var decimal = document.getElementById('companydd'); 
        decimal = req.responseText; 
		//alert(decimal).value;
      } 
    }
   // clear();
  } 
  function clear(){ 
    var key = document.getElementById("customers"); 
    key.value=""; 
  }
  function focusIn(){ 
    document.getElementById("customers").focus();
  }






<html> 
<head> 
<script src="Customer4.js"></script> 
<title>Hello World</title> 
</head> 
<body> 
 
<form method="post"  action="page_to_post_information.html" name="f1"> 
Select a Customerb: 
<select name="customers" onchange="showCustomer(this.value)"> 
<option value="-">--</option> 
<option value="1">Ame</option> 
<option value="David">David</option> 
<option value="1">Happy </option> 
</select> 
 
 
 
<select name="companydd"> 
         
</select> 
</form> 
 
<b><span id="companyname"></span></b><br /><b><span id="companyname"></span></b><br /><b><span id="companyname"></span></b><br /> 
<span id="contactname"></span><br /> 
<span id="address"></span> 
<span id="city"></span><br/> 
<span id="country"></span> 
 
 
 
</body> 
</html>

Open in new window

LVL 3
gazdzidAsked:
Who is Participating?
 
Sathish David Kumar NArchitectCommented:
Wrong

1. ur not return that  Result set value . ur only printing !!

2. I dont know y use like this decimal = req.responseText;

3.in ur Jsp u never user decimal ;

4. <select name="companydd">
         
</select>

u didnt mention the code any where for companydd

Then how the value will set !!
0
 
asafadisCommented:
You tell us... is it working?   If not, what's happening?  Any error message?
0
 
gazdzidAuthor Commented:
asafadis:
Sorry that I did not tell you,  It is not working

dravidnsr:

Thank you for your reply,
Onchange of "customers" I want the javascript to call the customer4.java returning vales of select statement to thdropdown labeled "companydd".

Please note at this point in time I do realize that the value passed to js is not used but in the future it will be.  currently, I am only trying to dynamically populate a dropdow using a select statement..
0
 
gazdzidAuthor Commented:
sorry, clening up old questions
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.