i have one table in database item master..if i select one item throug combo box than other combobox show item price only select item name... how i can implement through jsp in a single jsp page.
We have used table item having fields itemId, itemName, itemPrice.
1)items.jsp:
<%@page import="java.sql.*"%> <%@page import="java.util.*"%> <html> <head> <script language="javascript" type="text/javascript"> 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= "price.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("item").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/register","root","root";); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("Select * from item"); while(rs.next()){ %> <option value="<%=rs.getString("itemName")%>"><%=rs.getString("itemName")%></option> <% } %> </select> <br> <div id='item'> <select name='item' > <option value='-1'></option> </select> </div> </body> </html>
2)price.jsp:
<%@page language="java" import ="java.sql.*" %> <% String itemname=request.getParameter("count"); String buffer="<select name='state'><option value='-1'>Select</option>"; Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root","root";); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("Select * from item where itemName='"+itemname+"' "); while(rs.next()){ buffer=buffer+"<option value='"+rs.getString("itemPrice")+"'>"+rs.getString("itemPrice")+"</option>"; } buffer=buffer+"</select>"; response.getWriter().println(buffer); %>
i want to answer in single page means only one jsp page...in above code you mention two .jsp file but i have one .jsp file as well as one database table so tell me appropriate solution for that....