Reputation: 7389
I got this little code snippet from one of my JSP
files:
<c:when test="${not empty param['filePath'] && not empty param['revision']}">
<c:out value="${sessionScope.fileHelper.getContentsForPath(param.filePath,param.revision)}" escapeXml="false"/>
</c:when>
Unfortunately I have to migrate back to Servlet 2.5
, currently I was using 3.0
.
The problem with this is, that EL (Expression Language)
does not support calling methods like this in prior versions. So I asked me how to accomplish the same thing with 2.5
compatible code.
The fileHelper
gets added to the sessionScope
in a different JSP
file like:
<jsp:useBean id="fileHelper"
class="de.myPackage.util.FileHelper" scope="session" />
What I tried was:
<%@ page import="de.myPackage.util.FileHelper"%>
<c:when test="${not empty param['filePath'] && not empty param['revision']}">
<c:out value="<%=(FileHelper)session.getAttribute("fileHelper").getContentsForPath(request.getParameter("filePath"),(String)request.getParameter("revision"))%>" escapeXml="false"/>
</c:when>
But this doesn't work since it writes:
The method getContentsForPath(String, String) is undefined for the type Object.
Any ideas ?
Upvotes: 0
Views: 94
Reputation: 62854
You have to wrap the cast session object within ()
to use it's .getContentsForPath()
method. Something like this:
((FileHelper) session.getAttribute("fileHelper")).getContentsForPath(...)
Upvotes: 1