Ragazzi,
un saluto a tutti. Chiedo il vostro aiuto per un semplicissimo quesito. Quanto vi riporto sotto corrisponde ad un metodo per leggere un semplicissimo valore inserito nel file di configurazione web.xml; premetto che sotto NetBeans ha sempre funzionato mentre ora sotto Eclipse non funziona più e da un errore. Credo che possa dipendere da qualche risorsa esterna che non ho importato o non ho correttamente importato. Guardate sotto e capirete. Grazie a tutti per il tempo dedicatomi! PS: ho già importato junit4.
ECCO LA CLASSE UtilityConfig, nel package java.main.utility:
/*
* UtilityConfig.java
*
* Created on 28 gennaio 2008, 16.31
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package java.main.utility;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
*
* @author yohi
*/
public class UtilityConfig {
/**
* Creates a new instance of UtilityConfig
*/
public UtilityConfig() {
}
public String UtilityGetParameter(String ParName){
Context ctx = null;
String ParValue =null;
try {
ctx = new InitialContext();
ParValue =(String) ctx.lookup("java:comp/env/"+ParName);
} catch (NamingException e) {
e.printStackTrace();
return null;
}
return ParValue;
}
}
Ecco il frammento della pagina in cui la richiamo (vi risparmio tutta la pagina per non abusare della vostra disponibilità):
<%
UtilityConfig myParGet = new UtilityConfig();
String defLanguage = myParGet.UtilityGetParameter("defaultLanguage");
%>
Ed ecco l'errore restituito:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Exception in JSP: /unknow.jsp:29
26: String ParValue =null;
27:
28: ctx = new InitialContext();
29: ParValue =(String)ctx.lookup("java:comp/env/"+"DefaultLanguage");
30:
31: %>
32:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:355)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
root cause
javax.servlet.ServletException: Name DefaultLanguage is not bound in this Context
org.apache.jasper.runtime.PageContextImpl.doHandle PageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePa geException(PageContextImpl.java:774)
org.apache.jsp.unknow_jsp._jspService(unknow_jsp.j ava:112)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
root cause
javax.naming.NameNotFoundException: Name DefaultLanguage is not bound in this Context
org.apache.naming.NamingContext.lookup(NamingConte xt.java:770)
org.apache.naming.NamingContext.lookup(NamingConte xt.java:140)
org.apache.naming.NamingContext.lookup(NamingConte xt.java:781)
org.apache.naming.NamingContext.lookup(NamingConte xt.java:140)
org.apache.naming.NamingContext.lookup(NamingConte xt.java:781)
org.apache.naming.NamingContext.lookup(NamingConte xt.java:153)
org.apache.naming.SelectorContext.lookup(SelectorC ontext.java:137)
javax.naming.InitialContext.lookup(Unknown Source)
org.apache.jsp.unknow_jsp._jspService(unknow_jsp.j ava:75)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.25 logs.

Rispondi quotando