bene....
grazie al prezioso aiuto di r@avem@ster abbiamo fatto la versione java delle select dinamiche.
la servlet e il web xml sono quelli indicati prima. Il main.jsp va modificato nel seguente modo:
codice:<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <% List provincia = new ArrayList(); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String filename = "C:\\Documents and Settings\\minicgag\\Desktop\\miei scripts\\Database Venditori\\Database_Venditori.mdb"; //String filename = "D:\\JONAS_4_8_4\\webapps\\autoload\\callc\\registrochiamate.mdb"; String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="; database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end // now we can get the connection from the DriverManager Connection con = DriverManager.getConnection( database ,"",""); Statement s = con.createStatement(); String query1 = "select * from provincia where attivo = 'si'"; s.execute(query1); ResultSet rs = s.getResultSet(); if(rs!=null){ while(rs.next()){ provincia.add(rs.getString(1)); provincia.add(rs.getString(2)); } } con.close(); // close the Connection to let the database know we're done with it s.close(); } catch(Exception e){ e.printStackTrace(); } finally{ try { } catch (Exception e) { e.printStackTrace(); } } %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <%@page import = "java.util.ArrayList" %> <%@page import = "java.util.List" %> <%@page import = "java.sql.*" %> <script language="javascript" type="text/javascript"> <!-- var http = createRequestObject(); var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null; function createRequestObject() { var ro; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ ro = new ActiveXObject("Microsoft.XMLHTTP"); }else{ ro = new XMLHttpRequest(); } return ro; } function addElement(ogg,val,text){ var newOption; newOption = document.createElement("option"); newOption.value = val; newOption.text = text; ogg.add(newOption, where); } function removeElement(ogg){ if(ogg.options.length > 0){ while (ogg.options.length) { ogg.remove(0); } } } function disabledElement(ogg,val){ document.getElementById(ogg).disabled = val; } function loadingProvince(oggId){ var id = document.getElementById(oggId).value; http.open('GET','do.getComune?prov='+id, true); http.onreadystatechange = getComune; http.send(null); } function getComune(){ var State = document.getElementById('l2'); removeElement(State); id = document.getElementById('Select_provincia').value; if(id == 'sel'){ disabledElement('l2',true); addElement(State,'sel','Seleziona prima un Continente:'); }else{ if(http.readyState == 4){ if (http.status == 200) { var response = http.responseText; document.getElementById("select2").innerHTML = response; disabledElement('l2',false); } }else{ addElement(State,'sel','Loading...'); } } } //--> </script> </head> <form name="form"> <div id="content"> <div id="label1"> Select 1 </div> <div id="select1"> <select id="Select_provincia" name="Select_provincia" onchange="loadingProvince('Select_provincia')" > <%for(int i=0;i<provincia.size();i=i+2){ %> <option <%if(provincia.get(i+1)=="Milano"){%> selected="selected" <%}%> value="<%=provincia.get(i) %>"><%=provincia.get(i+1) %></option> <%} %> </select> </div> <div id="label2"> Select 2 </div> <div id="select2"> <select name="l2" id="l2" disabled> <option value="sel" selected="selected">Seleziona un comune:</option> </select> </div> </div> </form> </body> </html>
Spero di esservi stato di aiuto... per tutti quelli che come me, ci hanno sbattuto parecchio la testa
![]()


						
					
					
					
						
  Rispondi quotando