Question
getting the ServletContext in CF
I am trying basically to interact with a Java class file
installed under WEB-INF/classes. I want to pass the ServletContext
for cf to my new class when I instantiate an object from it.
What I wanted to do was to create an instance of my class through <cfobject> and then use init(getPageContext.getServletContext).
So I used:
<cfscript>
cfServlet = getPageContext().getServletContext();
url_mappings = CreateObject("java", "com.dev.myFilter.UrlMapper");
</cfscript>
Then I went to initialize this new object and pass the ServletContext into it:
url_mappings.init(cfServlet).
This returns an error because (as I soon discovered) the object "cfServlet" gotten from the first line is of class "coldfusion.runtime.ServletContextWrapper", and my Constructor method for my class is designed to handle a ServletContext object.
I also tried making a constructor method that takes argument of time coldfusion.runtime.ServletContextWrapper, but I still got an error in CF that there are no constructor methods designed to handle argument of type coldfusion.runtime.ServletContextWrapper, which is wierd!
In my class file I have these 2 constructor methods as a test, so that I am explicitly handling ServletContextWrappers:
UrlMapper(ServletContextWrapper servletcontextwrapper) {
this.ReadFile();
}
// Constructor w/out filename arg
UrlMapper(ServletContext servletcontext) {
UrlMapper.servletcontext = servletcontext;
this.ReadFile();
}
But this still throws an error in my CFM template!
"Unable to find a constructor for class com.webworld.filter.UrlMapper that accepts parameters of type ( coldfusion.runtime.ServletContextWrapper ). "
Is there any way to get around this, either in CF by casting this ServletContextWrapper object to a ServletContext, or by simply getting the actual ServletContext?
--- Thanks
What I wanted to do was to create an instance of my class through <cfobject> and then use init(getPageContext.getServletContext).
So I used:
<cfscript>
cfServlet = getPageContext().getServletContext();
url_mappings = CreateObject("java", "com.dev.myFilter.UrlMapper");
</cfscript>
Then I went to initialize this new object and pass the ServletContext into it:
url_mappings.init(cfServlet).
This returns an error because (as I soon discovered) the object "cfServlet" gotten from the first line is of class "coldfusion.runtime.ServletContextWrapper", and my Constructor method for my class is designed to handle a ServletContext object.
I also tried making a constructor method that takes argument of time coldfusion.runtime.ServletContextWrapper, but I still got an error in CF that there are no constructor methods designed to handle argument of type coldfusion.runtime.ServletContextWrapper, which is wierd!
In my class file I have these 2 constructor methods as a test, so that I am explicitly handling ServletContextWrappers:
UrlMapper(ServletContextWrapper servletcontextwrapper) {
this.ReadFile();
}
// Constructor w/out filename arg
UrlMapper(ServletContext servletcontext) {
UrlMapper.servletcontext = servletcontext;
this.ReadFile();
}
But this still throws an error in my CFM template!
"Unable to find a constructor for class com.webworld.filter.UrlMapper that accepts parameters of type ( coldfusion.runtime.ServletContextWrapper ). "
Is there any way to get around this, either in CF by casting this ServletContextWrapper object to a ServletContext, or by simply getting the actual ServletContext?
--- Thanks
