Per il momento almeno la auth.jsp è sistemata, ho dovuto cambiare il codice come segue:
(rispetto a prima ho portato il file data.txt nella WEB-INF)
e il web.xml come:codice:ServletConfig cfg = getServletConfig(); String pathUser = cfg.getInitParameter("pathUser"); DataFile df = new DataFile(getServletConfig().getServletContext().getRealPath("/")+pathUser);
Ora però ho un problema nella servlet StateRedirect per la quale non riesco a richiamare i parametri di inizializzazione pathUser e pathUrl come avrai visto dal web.xml sopra.codice:<servlet> <servlet-name>auth</servlet-name> <jsp-file>/auth.jsp</jsp-file> <init-param> <param-name>pathUser</param-name> <param-value>/WEB-INF/data.txt</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>auth</servlet-name> <url-pattern>/auth.jsp</url-pattern> </servlet-mapping> <servlet> <servlet-name>StateRedirect</servlet-name> <servlet-class>StateRedirect</servlet-class> <init-param> <param-name>pathUser</param-name> <param-value>/WEB-INF/data.txt</param-value> <param-name>pathUrl</param-name> <param-value>/WEB-INF/URL.txt</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>StateRedirect</servlet-name> <url-pattern>/poolServlet/StateRedirect</url-pattern> </servlet-mapping>
Per estrarre i parametri di inizializzazione sovrascrivo il metodo init nella seguente maniera:
Per certo ti posso dire che la variabile pathUser =null ma non ho capito perchè!codice:public void init() throws ServletException { try{ ServletConfig cfg = getServletConfig(); String pathUser = cfg.getInitParameter("pathUser"); String pathUrl = cfg.getInitParameter("pathUrl"); df = new DataFile(getServletConfig().getServletContext().getRealPath("/")+pathUser); URL = new URLTable(getServletConfig().getServletContext().getRealPath("/")+pathUrl); }catch(IOException e){ }
Ciao e grazie per il tuo aiuto.

Rispondi quotando