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



Home Answers Viewqa Ajax ajax code please help to solve this.
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


rahulmohanty
ajax code please help to solve this.
2 Answer(s)      2 years and 6 months ago
Posted in : Ajax


in this i am trying to get data from datbase and put it in combo box and then display it down using table and use ajax onchange but when i am trying to do so it show some error

viewapplicants.jsp

<a href="birth.do?submit=applicantsforbirthcertificate">Applicants for Birth Certificate</a>

when i am clicking this it goes to database and retrieve

viewbirthapplicants.jsp

<%@ page language="java" pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>



<jsp:directive.page import="p.form.BirthForm"/>
<jsp:directive.page import="java.util.ArrayList"/>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License

Name       : Rain on Leaves  
Description: A two-column, fixed-width design with dark color scheme.
Version    : 1.0
Released   : 20101114

-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Rain on Leaves   by Free CSS Templates</title>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />

<script type="text/javascript">
var ob;
  function fun(str)
   {
      try
         {
            ob=new XMLHttpRequest();
         }
       catch(e)
         {
            try
                {
                    ob=new ActiveXObject("Msxml2.XMLHTTP");
                }
            catch(e)
            {

             try
                {
                    ob=new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch(e)
                {
                    alert("browser exception");
                    return false;
                }
          }
    }

  function fun5()
    {
        if(ob.readyState==4)
            {

                document.getElementById("result").innerHTML=ob.responseText;
            }
       }
  alert(1);
  ob.onreadystatechange=fun5;
  var url="/mc/birth.do";

  url=url+"?id="+str;

  url=url+"&s="+Math.random();
  ob.open("GET",url,true);
  ob.send();
  alert(2);


   }              
</script>

</head>
<body>
<div id="wrapper">
    <div id="menu">
        <ul>
            <li class="current_page_item"><span>
            <a href="adminhome.jsp">Home</a></span></li>
            <li><a href="contactus.jsp">contact us</a></li>
            <li><a href="aboutus.jsp">about us</a></li>

            <li><a href="help.jsp">help instruction</a></li>

        </ul>
    </div>
    <!-- end #menu -->
    <div id="header">
        <div id="logo">
            <h1><marquee behavior="alternate"  scrollamout="5"><center></center><em>
<FONT face="Algerian" size="6" color="yellow">Municipal Corporation (MC)</FONT></em></center></marquee><br /></h1>
            </div>
    </div>
    <!-- end #header -->
    <div id="page">
        <div id="content">
            <div class="post">
                <h2 class="title"><a><marquee loop="1" behavior="slide"><font face="Forte" color="white" >VIEW BIRTH APPLICANTS</font></marquee></a></h2>

                     <ul>

                      <li><a href="viewapplicants.jsp">View Applicants Details</a></li>

                       </ul>
                       <br />
                       <br />
                       <br />
                       <br />
                       <br />

                       <html:form action="birth">
                       <table>
                        <% 
                        ArrayList<String> id=(ArrayList<String>)request.getAttribute("ID");
                        ArrayList<String> birthregno=(ArrayList<String>)request.getAttribute("BIRTH_REGISTRATION_NO");
                         %> 
                        <tr>
                        <td>Birth Reg No</td>
                        <td><html:select property="id" onchange="fun(this.value);">
                            <%
                               for(int i=0;i<id.size();i++)
                                   {
                                     %>
                                       <html:option value="<%=id.get(i) %>"><%=birthregno.get(i) %></html:option>
                                  <%} %>
                                 </html:select>
                                 </td></tr>



                   </table>



                   </html:form>

                       <div id="result">


                       <bean:write name="birthForm" property="msg"/> 
                      <bean:write name="birthForm" property="msg1"/>                


                         <div class="post">


            </div>
        </div>
    </div>
</div>          

    <!-- end #content -->
    <div id="sidebar">
            <ul>
                <li>

                    <ul>
                    <marquee loop="1" direction="up" behavior="slide" >
                    <font face="Kristen ITC">

                        <li><a href="workprofile.jsp">Work Profile</a></li>
                        <li><a href="updatewards.jsp">Ward Profile</a></li>
                        <li><a href="updatebudgetdetails.jsp">Budget</a></li>
                        <li><a href="updatehealthandsanitation.jsp">Health and Sanitation</a></li>
                        <li><a href="updatetenders.jsp">Tenders</a></li>

                        </font></marquee>


                    </ul>
                </li>

            </ul>
        </div>
        <!-- end #sidebar -->
    <div style="clear: both;"> </div>
    <!-- end #page -->
     <br />
                       <br />
                       <br />
                       <br />
                       <br />

    <div id="footer">
        <p><FONT color="black">Copyright (c) 2011 . All rights reserved. Design bY Pratyush Mahapatra</FONT></p>
    </div>
    <!-- end #footer -->
</div>

</body>
</html>

BirthAction class

public ActionForward applicantsforbirthcertificate(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)throws SQLException
    {
        BirthForm birthForm = (BirthForm) form;// TODO Auto-generated method stub
        DBLogic dblogic=new DBLogic();

        ArrayList<String> id=new ArrayList<String>();
        ArrayList<String> birthregno=new ArrayList<String>();

        ResultSet rs=dblogic.Applicantsbirthcertificate();


        while(rs.next())

        {

            id.add(rs.getString("BIRTHID"));
            birthregno.add(rs.getString("BIRTH_REGISTRATION_NO"));

        }

        request.setAttribute("ID", id);
        request.setAttribute("BIRTH_REGISTRATION_NO",birthregno);
        return mapping.findForward("viewbirthapplicants");
    }

    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)throws  IOException
    {

        BirthForm birth = (BirthForm) form;// TODO Auto-generated method stub

        PrintWriter out=response.getWriter();
        ResultSet rs=null;
        Connection con=null;
        Statement st=null;

         System.out.println(1);
        String id=request.getParameter("id");
         System.out.println(2);
        Long brn=Long.parseLong(id);
         System.out.println(3);
        System.out.println("BIRTH_REGISTRATION_NO:"+brn);

         try

            {
                Class.forName("oracle.jdbc.driver.OracleDriver");
            con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","bmch","bmch");
                 st=con.createStatement();



                 System.out.println(id);



                 rs=st.executeQuery("select * from BIRTHCERTIFICATE where BIRTH_REGISTRATION_NO="+brn+"");

         System.out.println("id"+brn);

        if(rs.next())
        {

            out.println("<table border='3'><tr>");

            out.println("<th>Date of Birth</th><th>Sex</th><th>Name</th><th>Name of Mother</th><th>Name of Father</th><th>Permanent Address</th><th>Place of Birth</th><th>Hospital/institute Name</th><th>Address</th><th>Name of Town/village</th><th>Name of District</th><th>Name of State</th><th>Religion</th><th>Mother's Education</th><th>Father's Education</th><th>Father's Occupation</th><th>Mother's Occupation</th><th>Age of Mother</th><th>No of Born of Child</th><th>Type of Attention at Delivery</th><th>Method of Delivery</th><th>Birth Weight(in kg)</th><th>Duration of Pergnancy(in week)</th><th>Oder of Birth</th><th>Informant Name</th><th>Address</th><th>Approved</th><th>Reject</th></tr>");      

            out.println("<td>");out.println(rs.getLong("BIRTHID"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("DATE_OF_BIRTH"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("SEX"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("NAME_OF_FATHER"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("NAME_OF_MOTHER"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("PERMANENT_ADDRESS"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("PLACE_OF_BIRTH"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("HOSPITAL/INSTITUTE"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("ADDRESS"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("NAME_OF_TOWN/VILLAGE"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("DISTRICT"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("STATE"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("RELIGION"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("MOTHER'S_EDUCATION"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("FATHER'S_OCCUPATION"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("MOTHER'S_OCCUPATION"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("FATHER_EDUCATION"));out.println("</td>");
            out.println("<td>");out.println(rs.getLong("AGE_OF_MOTHER"));out.println("</td>");
            out.println("<td>");out.println(rs.getLong("NO_OF_BORN_OF_CHILD"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("ORDER_OF_BIRTH"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("INFORMANENT_NAME"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("INFORMANENT_ADDRESS"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("TYPE_OF_ATTENTION_AT_DELIVERY"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("METHOD_OF_DELIVERY"));out.println("</td>");
            out.println("<td>");out.println(rs.getLong("BIRTH_WEIGHT(IN_KG)"));out.println("</td>");
            out.println("<td>");out.println(rs.getString("DURATION_OF_PERGNANCY"));out.println("</td>");

            out.println("<td>");out.println(rs.getString("NAME"));out.println("</td>");


            out.println("<td></tr></table>");

        }
        else 
        {
            out.println("Data not found");
        }
            }
        catch(Exception err)
        {
            System.out.println(err.getMessage());
        }
            return null;

    }   

please help me when i am running this it show an error

exception 

javax.servlet.ServletException: java.lang.NumberFormatException: null
    org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
    org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

java.lang.NumberFormatException: null
    java.lang.Long.parseLong(Long.java:372)
    java.lang.Long.parseLong(Long.java:461)
    p.action.BirthAction.execute(BirthAction.java:102)
    org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.24 logs.

Advertisement
View Answers

April 16, 2012 at 5:46 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   
      }   
      }

      function showCity(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="city.jsp";
      url +="?count=" +str;
      xmlHttp.onreadystatechange = stateChange1;
      xmlHttp.open("GET", url, true);
      xmlHttp.send(null);
      }
      function stateChange1(){   
      if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){   
      document.getElementById("city").innerHTML=xmlHttp.responseText   
      }   
      }
      </script>  
      </head>  
      <body>  
      <table border="1">
      <tr><th>Country</th><th>State</th><th>City</th></tr>
      <tr><td>
      <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> 
      </td>
      <td id='state'><select name='state' >  
      <option value='-1'></option>  
      </select>
      </td>
       <td id='city'> <select name='city' >  
      <option value='-1'></option>  
      </select>   
      </td>
      </tr>
      </table>
      </body> 
      </html>


April 16, 2012 at 5:47 PM


continue..

2)state.jsp:

<%@page import="java.sql.*"%>
<%
String country=request.getParameter("count");  
 String buffer="<select name='state' onchange='showCity(this.value);'><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);
 }

 %>

3)city.jsp:

<%@page import="java.sql.*"%>
<%
String state=request.getParameter("count");  
 String buffer="<select name='city'><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 city where stateid='"+state+"' ");  
   while(rs.next()){
   buffer=buffer+"<option value='"+rs.getString(2)+"'>"+rs.getString(3)+"</option>";  
   }  
 buffer=buffer+"</select>";  
 response.getWriter().println(buffer); 
 }
 catch(Exception e){
     System.out.println(e);
 }
 %>

We have created 3 dependent dropdown. You can create the fourth one similarly.

For the above code, we have used 3 database tables:

1)country

CREATE TABLE `country` (                                 
           `countryid` bigint(255) NOT NULL auto_increment,       
           `countryname` varchar(255) default NULL,               
           PRIMARY KEY  (`countryid`)                             
     )

2)state

CREATE TABLE `state` (                                   
          `stateid` bigint(255) NOT NULL auto_increment,         
          `countryid` int(255) default NULL,                     
          `state` varchar(255) default NULL,                     
          PRIMARY KEY  (`stateid`)                               
        )

3)city

CREATE TABLE `city` (                                    
          `cityid` bigint(255) NOT NULL auto_increment,          
          `stateid` int(255) default NULL,                       
          `city` varchar(255) default NULL,                      
          PRIMARY KEY  (`cityid`)                                
        )


Related Tutorials/Questions & Answers:
ajax code please help to solve this........
ajax code please help to solve this.  in this i am trying to get data... null; } please help me when i am running this it show an error... and use ajax onchange but when i am trying to do so it show some error
Please Help To Solve My Problem
Please Help To Solve My Problem  PHP I Have 6 Textbox and 1 ok... With B Team when A Team Play With B Team Again Then Generate Error. I Am Solve... Are There Then It's Large Codding So I Need To Help To Another Way To Do
Advertisements
please help me to solve this question about array
please help me to solve this question about array  write a program...() > 1) System.out.println("It is not character. Please enter...."); } } } Is this code is fruitful for you. +++++++++ knapster +++++++++  
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP   The Task Write a class whose objects will represent students. The class should have three fields for representing a student‚??s
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP   Write a class whose objects will represent students.The class should have three fields for representing a student√Ę‚?¨‚?Ęs name, this student√Ę‚?¨‚?Ęs
Please help with this code
Please help with this code  I need some help getting the Search method below to work with the menu, and I also cannot figure out how to get my bubble sort to work. I've spent a long time on this and think my brain is just fried
Please help me to solve these programs in Python - Java Beginners
Please help me to solve these programs in Python  1. Write a program that prints an n-level stair case made of text. The user should choose the text character and the number of stairs in the stair case
could anyone please help with the code.
could anyone please help with the code.  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException...(request, response); } } could anyone please check the code. If i enter
please solve this program
please solve this program  Build a package EMPPACK that contains one stored function Validatesal() and two stored procedures Insertemp() and Getempdetails().The Insert_emp() procedure inserts a particular employee
please solve the programme
please solve the programme  Develop a java program to find the roots of a quadratic equation ax2+bx+c=0, with the following specification :- Class name :- Quad Data members float a,b,c,d, with a,b,c are the co-efficient
please help me to write a code for this program
please help me to write a code for this program   1 1 1 1 2 2 1 1 3 4 3 1 1 4 7 7 4 1
please help me to write a code for this program
please help me to write a code for this program   1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
please help me solve this problem when i am create database connection using servlecontext
please help me solve this problem when i am create database connection using... servletcontext . in this code when i login first time it will exceute sucessfully... understand what is the problem .... the code are as follows. the servlet context
Not sure whats wrong with my code HELP PLEASE?!?!
Not sure whats wrong with my code HELP PLEASE?!?!  I cant figure out what I am doing wrong in my code can anyone help me out??? Grades function computeGrade( ) { var hw, lab, midt, fin, avg; hw = parseFloat
please help me to give code - Java Beginners
please help me to give code  Write a function with a signature cheerlead(word) that prints a typical cheer as follows. The word robot: Gimme an R Gimme an O Gimme a B Gimme an O Gimme a T What did you give me? ROBOT
please help me to give code - Java Beginners
please help me to give code  Write a function, sliding(word, num)that behaves as follows. It should print out each slice of the original word having length num, aligned vertically as shown below. A call to sliding(examples, 4
Please help me fix this code - MobileApplications
Please help me fix this code   Please help me in this area of code... in the background of the forms in this code i want to sum all expenses amount... expenses)", "Please fill all required field \n \n * This signify required field
please help me to give code - Java Beginners
please help me to give code  Write a program that uses loops to generate an n x n times table. The program should get n from the user. As a model here is a 4 x4 version: | 1 2 3 4
please help me to give code - Java Beginners
please help me to give code  Write a program that prints an n-level stair case made of text. The user should choose the text character and the number of stairs in the stair case * ** *** ****   Hi friend
please help me to give code - Java Beginners
please help me to give code  Write a program that reads a file named famous.txt and prints out the line with the longest length. In the case of a tie, you may print out only one of them. For example in the file: Alan Turing
help me to solve this question
help me to solve this question  Write a program that inputs a series of integers into an array. The numbers are in the range 0 to 100. Calculate and display : a) The Largest number b) The Smallest Number c)The sum of the numbers
help me to solve this question
help me to solve this question   A user needs to key in data... name, School, course code, course name, session, semester A user can edit the data... code, course name, session, semester A user can display all the records
Please help me to modify my java code from php code
]; } } I tried like this (see below JSP code) ... but this is not giving me the exact result as the above PHP code is giving. So please help me to convert...Modify Java code from PHP Code  i want to covert this php code int
help me to solve this problem..
help me to solve this problem..  Given below is a class definition for Book. Type and compile the class, and answer the following questions: class Book { String title; //book‚??s title double price; //book‚??s price
help me to solve this question...
help me to solve this question...  Given below is a class definition for Book. Type and compile the class, and answer the following questions: class Book { String title; //book‚??s title double price; //book‚??s
Please help me to modify my java code from php code
Please help me to modify my java code from php code  i want to covert...) ... but this is not giving me the exact result as the above PHP code is giving. So please... same, as they alter it before. Please help me on this topic "how to order rows
I need help on my Java code.... please please help me out!?
I need help on my Java code.... please please help me out!?  Well my code is supposed to ask for an input file and then (ex: input.txt), read... in the file. Also it should be displayed on the screen. However my code doesn't display
please help
please help  please send me the code of dynamic stack in java without using the built in functions
please any one can help me to write a code for this question?
please any one can help me to write a code for this question?  1) Copy one file content to other? 2) Count the number of words in a file
Please help me to write a code for add contacts to groups in a website?
Please help me to write a code for add contacts to groups in a website?   Iam developing a site. In that site I need to write code for Groups... send a code for this? Please make it fast
plz help meto solve this question
plz help meto solve this question  for a file that exist what will be the length() method in the file class return
Advertisements
 

 

 

DMCA.com