I have a java class which get an object reading a xml file, my problem is that i recieve a error message when i try to instantiate the class sending an argument from a jsp, i tried sending PageContext, request and session and i´ve got the same error (Java ServletException init the class).
I need the ServletContext in order to get the resource of the xml file. If anybody can help me, i´ll appreciate suggestions.
In a JSP, the ServletContext is stored in the implicit "application" object. If you must pass the ServletContext (because that is the way the class is written), then pass the "application" object.
A better way to do this would be to pass the data required by the class rather than the ServletContext itself.
// Create DataLoader object:
DataLoader loader = new DataLoader();
// Load data from the ServletContext path:
java.net.URL resource = application.getResouce("my.xml");
Object result = loader.load(resource);