Ciao a tutti.
È possibile utilizzare l'oggetto application all'interno delle servlet? Per esempio in questo modo:
codice:public abstract class Bootstrap extends HttpServlet { @Override public void init() { Connection dbConnection = (Connection) application.getAttribute("dbConnection"); if (dbConnection == null) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); dbConnection = DriverManager.getConnection( "jdbc:mysql://host:3306/dbname", "user", "password"); } catch(Exception e) { System.err.println("Unable to connecto to db. Error: " + e.getMessage()); System.exit(1); } } application.setAttribute("dbConnection", dbConnection); } }


Rispondi quotando