Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet servlet program
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Gopi
servlet program
1 Answer(s)      6 years and 2 months ago
Posted in : JSP-Servlet



Advertisement
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
how to write servlet program in eclipse?
how to write servlet program in eclipse?  how to write servlet program in eclipse
Advertisements
servlet program for data store in oracle?
servlet program for data store in oracle?  how to store data in oracle through servlet program
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/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
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
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
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
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
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
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
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
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.*; import java.util.... the response from the servlet page. DataInputStream
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
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
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
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
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
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
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
program
program  develop a servlet to insert the data in the database from our program in the table stored in the database
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
 

 

 

DMCA.com