struts with ajax

struts with ajax

i have two selectboxex.the first selectbox contains all states.when i select one state then the cities corresponing to that state will appear in another textbox.i want code for this in struts and ajax

View Answers

March 25, 2011 at 3:25 PM

1)country.jsp:

 <%@page import="java.sql.*"%>
 <html>
      <head>  
      <script language="javascript" type="text/javascript">  
      var xmlHttp  
      var xmlHttp
      function showState(str){
      if (typeof XMLHttpRequest != "undefined"){
      xmlHttp= new XMLHttpRequest();
      }
      else if (window.ActiveXObject){
      xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
      }
      if (xmlHttp==null){
      alert("Browser does not support XMLHTTP Request")
      return;
      } 
      var url="state.jsp";
      url +="?count=" +str;
      xmlHttp.onreadystatechange = stateChange;
      xmlHttp.open("GET", url, true);
      xmlHttp.send(null);
      }

      function stateChange(){   
      if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){   
      document.getElementById("state").innerHTML=xmlHttp.responseText   
      }   
      }

      </script>  
      </head>  
      <body>  
      <select name='country' onchange="showState(this.value)">  
       <option value="none">Select</option>  
    <%
 Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
 Statement stmt = con.createStatement();  
 ResultSet rs = stmt.executeQuery("Select * from country");
 while(rs.next()){
     %>
      <option value="<%=rs.getString(1)%>"><%=rs.getString(2)%></option>  
      <%
 }
     %>
      </select>  
      <br>  
      <div id='state'>  
      <select name='state' >  
      <option value='-1'></option>  
      </select>  
      </div>  
      </body> 
      </html>

2)state.jsp:

<%@page import="java.sql.*"%>
<%
String country=request.getParameter("count");  
 String buffer="<select name='state' ><option value='-1'>Select</option>";  
 try{
 Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
 Statement stmt = con.createStatement();  
 ResultSet rs = stmt.executeQuery("Select * from state where countryid='"+country+"' ");  
   while(rs.next()){
   buffer=buffer+"<option value='"+rs.getString(1)+"'>"+rs.getString(3)+"</option>";  
   }  
 buffer=buffer+"</select>";  
 response.getWriter().println(buffer); 
 }
 catch(Exception e){
     System.out.println(e);
 }

 %>









Related Tutorials/Questions & Answers:
struts with ajax
struts with ajax  i have two selectboxex.the first selectbox contains all states.when i select one state then the cities corresponing to that state will appear in another textbox.i want code for this in struts and ajax
Ajax in struts application - Ajax
Ajax in struts application  I have a running application using struts and now i want to implement Ajax(for populating some search box) in it.The problem is that my jsp page is able to send the request to my Struts Action process
Advertisements
Struts 1.2 and ajax example
Struts 1.2 and ajax example  Struts 1.2 and ajax example with data from database
Struts and Ajax - Struts
Struts and Ajax  Is it possible to use Ajaxtags in an existing system that uses Struts and Dojo? Have anyone tryied
Ajax for Struts with Hibernate Application - Struts
Ajax for Struts with Hibernate Application  Hi All, I have developed a registration page with country and state drop downs. I want to use ajax for these drop downs with hibernate support. Kindly help for this , thanks
Struts in AJAX - Framework
Struts in AJAX  Dear Deepak Sir, How to use ajax in Struts..., VijayaBabu.M  Hi, Struts 2 provides inbuilt support for Ajax and Dojo. Its very easy to use Ajax in Struts 2 applications. Please check at http
Backbase AJAX for Struts
Backbase AJAX for Struts       Backbase AJAX for Struts is a complete AJAX - Struts programming framework build on top of any Struts and Eclipse which Pre-build AJAX-Struts components
Struts 2 + Ajax
Struts 2 + Ajax  hi , i am new in java ,i need a help I am setting the attribute in by session.setAttribute which is passes values to a jsp page... without refreshing. can anyone tell me the ajax code to do
struts(DWR) - Ajax
struts(DWR)  i want to pass a combo box value from my jsp page to servlet . where i had to done this by using DWR.. It is getting null value...").innerHTML = "ur browser doestnot support ajax
struts imagelink - Ajax
struts imagelink  i need one dropdown menu in that i have to select image AND i need one button when i clicks on that image will be open
Struts 2 Ajax
Struts 2 Ajax       In this section, we explain you Ajax based development in Struts 2. Struts 2 provides built... to the Struts 2 framework. Ajax allows the developers to develop GUI like web
Struts 2.2.1 Ajax Tags And Example
Struts 2.2.1 Ajax Tags And Example a autocompleter bind datetimepicker div head submit tabbedpanel textarea tree treenode
Reg: Tree view in Struts using ajax - Struts
Reg: Tree view in Struts using ajax  HI all, Can you figure... in all struts tld file.. please help me if you know thanks in advance? ... Struts Tag : 1)Struts download site http://struts.apache.org
Struts 1.2.9 (NB6.1) ? Problems with depend <html:select> and AJAX - Struts
Struts 1.2.9 (NB6.1) ? Problems with depend and AJAX  Hi I have 2 and one is depend to the other The 1st select I fill it of the DB... select value as a parameter How I do it with AJAX?? Maybe JQuery? Sorry
How to change value of div using Ajax in struts.
How to change value of div using Ajax in struts. In this example, we will introduce you to how to change value of div tag using Ajax in struts, without...;title>Struts Ajax example</title><sx:head /></head> <
using ajax and jsp (struts) to login and remain on same page.
using ajax and jsp (struts) to login and remain on same page.  I am a fresher... I can forward my login page to success page using struts, but I... know how to use struts to remain on same page. What about config file:- <
Introduction to Ajax.
to change value of div using Ajax in struts. Ajax validation...Introduction to Ajax. Ajax : Asynchronous JavaScript and XML Ajax... and dynamic web pages.  Before the Ajax, for accessing any data from
ajax
ajax  please describe the ajax
Ajax
Ajax  How to learn AJAX
Ajax
Ajax  Hi, What is Ajax? What is the use of Ajax? Thanks   Hi, Ajax is set of technologies used to develop dynamic web applications. In Ajax following technologies is used: a) JavaScript b) XML c) HTTP d) CSS Learn
Ajax
Ajax  how to impliment ajax in registration table using jsp-servlet
Ajax
Ajax  send the example to fetch the data from the server by using ajax in java. for ex:-if there are states which is used to display in frontend we use ajax. send it to me
Ajax
Ajax  how to include ajax in jsp page?   Hi, Please read Ajax First Example - Print Date and Time example.ADS_TO_REPLACE_1 Instead of using PHP you can write your code in JSP. Thanks
ajax
ajax  how to connect ajax with mysql without using php,asp or any other scripting language. please answer soon
Problem dispalying Country, City, State in JSP using Ajax in Struts Framework - JSP-Servlet
Problem dispalying Country, City, State in JSP using Ajax in Struts Framework  Hi, In my JSP page, I have used one div that adds some rows... showing data from database using ajax, jquery.. but it is not working.. It is because
Ajax - Ajax
Ajax  What is Ajax ? How one can use ajax with Java
ajax - Ajax
ajax  Hi all, I want ajax validation in struts1.0 , I tried from many days but, i cound't find solution.. I am attaching my code here. struts... ("Your browser does not support Ajax HTTP"); return; } var s
ajax
ajax  HI, In my application using ajax if i type a managername in the textbox it should display all the employees under the that manager... me reg this. thanks KK   Combobox box using Ajax in JSP   i
Ajax
ajax where instead of a link a radio button can fetch the data and can populate a table.If ajax can be used,it would be a greater advantage.After fetching data
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
Ajax
options. I want to do it using ajax. My table is CREATE TABLE HT<em>
AJAX
ajax. My table is CREATE TABLE HTNEWMETER ( ID NUMBER (10) NOT NULL, METERNO
ajax for sturts - Ajax
ajax for sturts  Hi, I am trying to connect to the struts action class using ajax but I am getting error(not able to call actionclass),but when i use servlets I can call easily. how to solv it? plz help me... thanks
ajax
ajax  I am facing following problem, I am using ajax to get the data continousely without refreshing. Here i have devided a web page into 3 parts(top,left and right) using table in jsp. On the left part i am displaying some
AJAX - Ajax
AJAX  what is Ajax?WHAT IS THE USAGE OF IT?WHERE WE HAVE TO USE IT? GIVE ME EXPLANATION WITH EXAMPLE?  Hi friend, Ajax : Asynchronous JavaScript and XML or Ajax for short is new web development technique used
AJAX - Ajax
AJAX  What is AJAX?how we will use it in java?what is the use of AJAX?give me example?   hi friend, Ajax plays a major role... characteristics have made it popular among the users to develop their site using Ajax
Struts
Struts   How to retrive data from database by using Struts
STRUTS
STRUTS  MAIN DIFFERENCES BETWEEN STRUTS 1 AND STRUTS 2
STRUTS
STRUTS  MAIN DIFFERENCES BETWEEN STRUTS 1 AND STRUTS 2
Struts
Struts  what is SwitchAction in struts
Struts
Struts  how to learn struts
STRUTS
STRUTS   Request context in struts? SendRedirect () and forward how to configure in struts-config.xml
struts
struts  in industry, struts 1 and struts 2. which is the best? which is useful as a professuional   Have a look at the following link: Struts Tutorials
Struts
Struts  Tell me good struts manual
struts
struts  what are the 4 methods of struts framework
struts
struts shopping cart project in struts with oracle database connection  shopping cart project in struts with oracle database connection   Have a look at the following link: Struts Shopping Cart using MySQL
ajax programming
for developing Ajax based applications. Dojo is selected by Struts 2 for providing Ajax support in applications. Struts 2 Ajax In this section, we explain you Ajax based development in Struts 2.ADS_TO_REPLACE_4 PHP Ajax Following

Ads