
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.

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>

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`)
)