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



Home Answers Viewqa Struts struts with ajax
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sivapoojitha
struts with ajax
1 Answer(s)      3 years and 7 months ago
Posted in : Struts


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


Advertisement
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...="sx" %> <html> <head><title>Struts Ajax
Introduction to Ajax.
in struts. Ajax validation in struts2...Introduction to Ajax. Ajax : Asynchronous JavaScript and XML Ajax... and dynamic web pages.  Before the Ajax, for accessing any data from
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:- <
Ajax
Ajax  How to learn AJAX
ajax
ajax  please describe the 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. 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
Ajax - Ajax
Ajax  What is Ajax ? How one can use ajax with Java
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
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
in a tabular form. Same for >33kv We can use ajax where instead of a link a radio button can fetch the data and can populate a table.If ajax can be used
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
Advertisements
 

 

 

DMCA.com