servlet program

servlet program

View Answers

September 23, 2008 at 1:34 PM

Might be this code help u........

<html>

<head>
<script language="javascript">
var xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
function selctData(form)
{

var url = "/Data.java?r=" + new Date().getTime() ;
xmlObj.open("GET", url)

xmlObj.onreadystatechange = function()
{
if(xmlObj.readystate == 4 && xmlObj.status == 200)
{
var id = document.getElementById("second");
var result = xmlObj.responseText;
alert(result);
if(result != null){

var s = result.split(',');
var indx = 0;
for(indx=0; indx < s.length; indx++)
{
id.options[indx] = new Option(s[indx],s[indx]);
}
}
}
}
xmlObj.send(null);
}
</script>
</head>
<body>
<h1>On Select change data of another Select</h1>

<br>

<select id="second"></select>

</body>
</html>
----------------------------------
Data.java
==============

public class Data extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
int countryID=0;
String value = req.getParameter("country");
String time = req.getParameter("r");
System.out.println("R " +time);
System.out.println("vountry " + value);
String dbQuery1 = "Select country_ID FROM TB_countries WHERE country_name='" + value + "'";
String dbQuery2 = "";

PrintWriter out = res.getWriter();
String result="";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase";, "root", "");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(dbQuery1);
while(rs.next()){
countryID = rs.getShort("country_ID");
System.out.println("countryid " + countryID);
}
dbQuery2 = "Select state_name FROM TB_states WHERE country_ID=" + countryID;
rs = stmt.executeQuery(dbQuery2);
while(rs.next()){
result = result + rs.getString("state_name") + ",";
}
}catch(Exception ex){

System.out.println(ex.getMessage());

}
out.write(result);
out.flush();
out.close();
}

}


Thanks
Rajanikant









Related Tutorials/Questions & Answers:
servlet program - JSP-Servlet
servlet program  Hi All, I just want to write a servlet program where in i want to retreive some data(some names) through a sql query from a sql... the servlet is executed .can you please send me the code? I hope my requirement
problem in servlet program
problem in servlet program  Dear Sir, I have a problem to insert the Blob type data like as video file, audio file in the database using Servlet and html code
Advertisements
servlet program for data store in oracle?
servlet program for data store in oracle?  how to store data in oracle through servlet program
how to write servlet program in eclipse?
how to write servlet program in eclipse?  how to write servlet program in eclipse
jsp program - JSP-Servlet
jsp program  1.write a servlet program that finds out the given number is armstrong or not which has been submitted through a form? 2.create an application in jsp to redirect the request to any other page.  Hi Friend
jsp/servlet login program
jsp/servlet login program  <%@ page language="Java" import="java.sql.*" %> <HTML> <HEAD><TITLE>DataBase Search<...; </html> When I run the program, I get an error: The requested resource
program code - JSP-Servlet
program code  what is the program code for LOGINFORM USING SERVLETS? RESPOND SOON
program code - JSP-Servlet
program code  what is the program code for LOGINFORM USING SERVLETS? RESPOND SOON
program - JSP-Servlet
program  Example program on RequestDispatcher  Hi I am sending links, where u find about requestDispatcher method, how it work and. http://www.roseindia.net/javacertification/wcd-guide/machanism.shtml http
program of java - JSP-Servlet
program of java  hi friends... i hv faced a problem of jsp code.my problem is... i want to extract data from dropdown menu to the next jsp page..... and also i want to generate a serial no and with this serial no , i want
Program - JSP-Servlet
Program  Respected Sir, I urgently need a program in JSP and JDBC which will connect to MS-ACCESS for seeking the data of Employees whose fields are Emp_id and Emp_Name.. I need to Add,Delete,Modify and Query
Program urgent - JSP-Servlet
Program urgent  Respected Sir/Madam, I am R.ragavendran.. Actually my code shows the following output: There is a combo box which contains all the ID's present in the database.. When I click or select any of the ID
Program Urgent - JSP-Servlet
Program Urgent  Respected Sir/Madam, I am R.Ragavendran. I am in urgent need of the coding. My requirement is as follows: Beside Enter Employee ID text Box, There must be a small button. When user clicks this button, a small
Merging of java script with servlet program
Merging of java script with servlet program  how can we merge the java script with the any servlet program for making web application intractive.Is there any program you have.\please help me to sove out this problem
servlet program problem - Java Beginners
servlet program problem   i used ur servlet example prg with xml file of helloworld program and i run dat program in tomcat, it shows only the files in my specified directory but when i clicked dat file name it just displaying
jsp/servlet login program - JSP-Servlet
jsp/servlet login program  hello sir, well i have a problem with some code(loginbean.jsp),which i actually got from ur site: i am trying to create a login program where a new user will be registered and his/her details stored
how to compile and run servlet program
how to compile and run servlet program   hello sir/mam i hve installed tomcat5.5 version and also have jdk1.6.0_14 installed but not able to run it or compile i m doing it first tyme pls help me in sorting out this problem. i hve
Program Very Urgent.. - JSP-Servlet
Program Very Urgent..  Respected Sir/Madam, I am R.Ragavendran.. Thanks for your superb reply. I got the link you sent. But I find a simple problem which i hava tried my level best to solve.In the output, the text box
Image Program Urgent - JSP-Servlet
Image Program Urgent  Respected Sir/Madam, I am R.Ragavendran.. Actuaaly in the Image Selection coding which is produced below, I am getting the Emp ID in the Emp ID text box but not the exact Emp ID which I have selected
how to ruv servlet program in myeclipse blue edition?
how to ruv servlet program in myeclipse blue edition?  how to ruv servlet program in myeclipse blue edition?  Servlets are run in a web server. The servlet can be deployed to the web server as part of deploying your
how to connect j2me program with mysql using servlet?
how to connect j2me program with mysql using servlet?  my program...(a); } }; } servlet program is: import java.io....(); // Get the response from the servlet page
jsp program for bill generation - JSP-Servlet
jsp program for bill generation  hi, i just want to know how i write the jsp program for generation of bill for a gas connectivity systm  Hi Friend, Please provide some information like structure of bill. Thanks
how to run jdbc in jsp program - JSP-Servlet
how to run jdbc in jsp program  i want to use sql server 2005 in jsp program to store data.i know how to run simple program but this program i tried my best i am not able to do so.please give me the answer of this as soon
sample jsp-servlet-service-db program
sample jsp-servlet-service-db program  <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http
Program Arrow selection Most Urgent - JSP-Servlet
Program Arrow selection Most Urgent  Respected Sir/Madam, I am R.Ragavendran.. I got your coding which is highly appreciable.. As per my requiremennt,there are image buttons for each row in the database.. But i am
Simple Program Very Urgent.. - JSP-Servlet
Simple Program Very Urgent..  Respected Sir/Madam, I am R.Ragavendran.. Thanks for your superb reply. I find a simple problem which i have tried my level best to solve.In the output, the text box is receiving some other value
write a program in java to demonstrate the complete life cycle of servlet:
write a program in java to demonstrate the complete life cycle of servlet: ... for this program. my question is :Write a program in Java to demonstrate the complete life cycle of a Servlet
without writing web.xml file we can write servlet program
without writing web.xml file we can write servlet program  Sir Morning... Sir I have one Question "without writing web.xml file we can write servlet program". if yes which way? if no why? but without use Annotation........ Plz
session realtime usage program simple jsp program or servlet ,which understands me importance of session
session realtime usage program simple jsp program or servlet ,which understands... like client state storage scope.,but jsp or servlet realtime simple session related program whether it may be loginpage or anything must simple understanding
How to get the data from the database using Servlet or JSP program
by using servlet or jsp program by typing the output as like this below...How to get the data from the database using Servlet or JSP program  .... Actual problem is that i have a simple program in jsp in the sense to get data
program
program  develop a servlet to insert the data in the database from our program in the table stored in the database
Program - JSP-Servlet
Program - JSP-Servlet
program - JSP-Servlet
Jsp Program - JSP-Servlet
Program - JSP-Servlet
Program - JSP-Servlet
Error 500-Server are not find the jar file in the program of upload the file - JSP-Servlet
Error 500-Server are not find the jar file in the program of upload... a program to upload a file.I include the commons-fileupload-1.2.1.jar file in lib...)]: Servlet class UploadFile for servlet one could not be loaded because
servlet
servlet  how to interact with a servlet from a swing program
program
program  Develop a servlet to count how many times the servelt is accessed
servlet
servlet  i want a program for counting the no of times the servlet has been invoked
String Exception Program - JSP-Servlet
Servlet hello world example
Servlet by making Servlet hello world program. We will just write one program...;/servlet-mapping> </web-app>  Output from the program : Download... the Servlet from scratch. Servlet is a server side programming language. Servlet
Servlet
Servlet  What is Servlet
How to pass and catch HTML parameters to a Java program using REST services?(without using servlet/jsp)
How to pass and catch HTML parameters to a Java program using REST services?(without using servlet/jsp)  Hello, I am new to these technologies i.e.... and catch HTML parameters to a Java program using REST services?(without using
Servlet
Servlet  I want to know the steps to write a simple servlet program... .   Hello Friend, Follow these steps: Put servlet-api.jar inside the lib folder of apache tomcat. 1)create a servlet. import java.io.*; import
Servlet
Servlet  how to navigate one servlet page to another servlet page
program
program  any program of hotel or school management
Program
Program  hey please help me ... How can write multiple choice question paper using radio button.After submit calculate marks and display our marks... can any body help for me.using servlet,html   Here is a jsp test
program
program  program of jdbc using ms access for creating table

Ads