blue-genie
asked on
servlet context syntax
i have this .....
TreeNode rootNode = (TreeNode)getServletContex t().getAtt ribute("me diaLibRoot TreeNode") ; which resides in a back end section
now i have to recreate this in the front end section
now normally i have this ..
getServlet().getServletCon text().get Attribute( "rolms_fro nt_dir").t oString() to get to the front bit.
but now how do i set my rootNode of TreeNode type to get the servlet attribute?
i'm not sure if i'm explaining this properly but i'm hoping you guys will understand this when u see it.
TreeNode rootNode = (TreeNode)getServletContex
now i have to recreate this in the front end section
now normally i have this ..
getServlet().getServletCon
but now how do i set my rootNode of TreeNode type to get the servlet attribute?
i'm not sure if i'm explaining this properly but i'm hoping you guys will understand this when u see it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
objects, it returns a null, but the value is set when the server starts up - it's in the logs.
i'm thinking it doesn't know where the servletcontext is. so i have to set somethign to the rolms_front_dir bit, but then get another attribute.
i want to do something like this
Object value = pageContext.getServletConf ig().getSe rvletConte xt().getAt tribute("r olms_front _dir").toS tring();
out.println(value); //this prints out correctly
TreeNode rootNode=(TreeNode)value.g etAttribut e("mediaLi bRootTreeN ode");
the other bit gives me a cannot resolve symbol
symbol : method getAttribute (java.lang.String)
location: class java.lang.Object
TreeNode rootNode=(TreeNode)value.g etAttribut e("mediaLi bRootTreeN ode");
i'm thinking it doesn't know where the servletcontext is. so i have to set somethign to the rolms_front_dir bit, but then get another attribute.
i want to do something like this
Object value = pageContext.getServletConf
out.println(value); //this prints out correctly
TreeNode rootNode=(TreeNode)value.g
the other bit gives me a cannot resolve symbol
symbol : method getAttribute (java.lang.String)
location: class java.lang.Object
TreeNode rootNode=(TreeNode)value.g
where exactly is that code?
> TreeNode rootNode=(TreeNode)value.g etAttribut e("mediaLi bRootTreeN ode");
'value' is a string, it doesn't have a getAttribute method
do u mean:
TreeNode rootNode=(TreeNode) pageContext.getServletConf ig().getSe rvletConte xt().getAt tribute("m ediaLibRoo tTreeNode" );
> TreeNode rootNode=(TreeNode)value.g
'value' is a string, it doesn't have a getAttribute method
do u mean:
TreeNode rootNode=(TreeNode) pageContext.getServletConf
ASKER
that code is in the jsp in the front bit
thing is the servlet is in the back, and the attribute gets set there, and i'm trying to access it from the front.
The web application has a administration section and a front view.
thing is the servlet is in the back, and the attribute gets set there, and i'm trying to access it from the front.
The web application has a administration section and a front view.
ASKER
ok, part 2, we've managed to pull something back but...when we getClass().getName() returns TreeNode
but if we cast to TreeNode - throws a classcast exeptinon?
but if we cast to TreeNode - throws a classcast exeptinon?
can u post your code
ASKER
thanks objects.... appreciate it
my serlet on start up calls
treeNodeCreator.buildCours eListWithL earningPro gramesAsTr ee(getServ letContext ());
the buildCourse... method does a whole bunch of things then at the end
servletContext.setAttribut e("mediaLi bRootTreeN ode", rootNode);
in my jsp....
we've been fiddling around with this a bit, so might look a bit disjointed...
TreeNode rootNode = null;
try{
TreeNode rootNode =getServletContext().getCo ntext("/" + getServletContext().getAtt ribute("ro lms_admin_ dir")).get Attribute( "mediaLibR ootTreeNod e");
} catch (ClassCastException ce) {
out.println(ce.getMessage( ));
}
out.println("Object type: " + rootNode.getClass().toStri ng());//re turns TreeNode
i need what's returned by the servet attribute to be cast to the TreeNode so that i can access it's methods....
shout if this is still not enough.
my serlet on start up calls
treeNodeCreator.buildCours
the buildCourse... method does a whole bunch of things then at the end
servletContext.setAttribut
in my jsp....
we've been fiddling around with this a bit, so might look a bit disjointed...
TreeNode rootNode = null;
try{
TreeNode rootNode =getServletContext().getCo
} catch (ClassCastException ce) {
out.println(ce.getMessage(
}
out.println("Object type: " + rootNode.getClass().toStri
i need what's returned by the servet attribute to be cast to the TreeNode so that i can access it's methods....
shout if this is still not enough.
there is no casting in that code??
ASKER
yeah sorry
when we try TreeNode rootNode = (TreeNode)getServletContex t().getCon text("/" + getServletContext().getAtt ribute("ro lms_admin_ dir")).get Attribute( "mediaLibR ootTreeNod e");
it throws the error.
when we try TreeNode rootNode = (TreeNode)getServletContex
it throws the error.
> out.println("Object type: " + rootNode.getClass().toStri ng());//re turns TreeNode
that doesn't make sense, if u were getting a CCE then rootNode would be null and that line would not return TreNode
that doesn't make sense, if u were getting a CCE then rootNode would be null and that line would not return TreNode
ASKER
ok, like is said, we've been playing around with the code and putting out prints and trying all sorts of wierd stuff.
bottom line, when we return the attribute from the servlet attribute and do a getClass on it, it brings back TreeNode, however when we explicitly cast it to TreeNode it throws the exception.
bottom line, when we return the attribute from the servlet attribute and do a getClass on it, it brings back TreeNode, however when we explicitly cast it to TreeNode it throws the exception.
if thats the case then they must be different TreeNode classes.
ASKER
is that possible if they're both the same package and all?
ASKER
managed to come right, thanks for your efforts anyway.
ASKER
i have 2 folders, the admin and front bits, and in the front, i have a jsp that needs to get hold of that attribute.