Ciao, ho provato a seguire questo post (http://forum.html.it/forum/showthread/t-1130792.html ), ma non riesco a farlo funzionare.
Sono poco pratico non le servlet.Uso javabeans.
Questo è lo script usato in TestInserimento.jsp
Codice PHP:
<script language="javascript" type="text/javascript"> </script>
Nello stesso file ci sono le select:
<div id="label1"> Select 1 </div> <div id="select1"> <select id="Select_provincia" name="Select_provincia" onchange="loadingProvince('Select_provincia')" > <% Vector<Provincia>provincia=CP.getProvincia(); for(int i=0; i< provincia.size(); i++){ int idP = provincia.get(i).getIDProvincia(); out.println("<option value="+ idP+ ">" + provincia.get(i).getNomeProvincia() + "</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>
E questa è la servlet:
Codice PHP:
public class Getcomune extends HttpServlet{ /** * */ private static final long serialVersionUID = 1L; String prov=null; ResultSet rs=null; public void init(ServletConfig config) throws ServletException { // Always call super.init(config) first (servlet mantra #1) super.init(config); } public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); prov = req.getParameter("prov"); Statement s; try { Class.forName("com.mysql.jdbc.Driver"); String DbURL = "jdbc:mysql://.../xxxxx"; String username = "yyyyy"; String password = "zzzzzz"; Connection conn = DriverManager.getConnection(DbURL, username, password); s = conn.createStatement(); String query = "SELECT NomeComune FROM Comune WHERE IDProvincia='"+prov+"' ;"; System.out.println(query); s.execute(query); rs = s.getResultSet(); if (rs != null) {// if rs == null, then there is no ResultSet to view while ( rs.next() ){ // this will step through our data row-by-row } } s.close(); conn.close(); } catch(Exception e){System.out.println("ERROR: " + e);} req.getRequestDispatcher("TestInserimento.jsp").forward(req, res); } public void destroy() { } }
Dov'è l'errore?
Grazie