servlet program

Ads
 

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

Ads









Related Tutorials/Questions & Answers:
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
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
Advertisements
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
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
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
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
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
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
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
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
servlet
servlet  how to interact with a servlet from a swing program
servlet
servlet  i want a program for counting the no of times the servlet has been invoked
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  develop a servlet to insert the data in the database from our program in the table stored in the database
Servlet hello world example
by making Servlet hello world program. We will just write one program which print... the Servlet from scratch. Servlet is a server side programming language. Servlet... interface. Servlet are responsible to handle web request. The javax.servlet
servlet
servlet  is there any way to include pdf's in servlet
servlet
servlet  what are the methods and interfaces in the servlet api ?   Servlet Tutorials
Servlet
-pattern> </servlet-mapping> </web-app> The Error is C:\Program... the same error <web-app> <servlet> <servlet-name>InsertServlet</servlet-name> <servlet-class>InsertServlet</servlet
servlet
servlet  hi sir,this is ashok.i installed tomcat 6.0 and jdk-150.i checked the server it's working but when execute servlet program for the .class file it shows the errors javax.servlet is not exist.what can i do,please tell me
servlet
servlet  what are the all necessary configuration to run a servlet
servlet
servlet  I designed 1 html form & a servlet but when I click on form I don't get output of servlet Please help
servlet
servlet  I designed 1 html form & a servlet but when I click on form I don't get output of servlet Please help
servlet
servlet  i want to create a login page with servlet using database mysql? only in servlet not in jsp plzz help me out
Servlet
override Service method in the servlet when you extend GenericServlet to create servlet as it is mandatory to override it. But, when you extend HttpServlet to create a servlet then you can't override service method as there is a need to override
servlet
servlet  how to create a login form using servlet using submit,edit delete button
servlet
servlet  dear sir servlet and html not run on eclips plz help me

Ads