Friday, 15 July 2011

jsp - Calling Java Method from Servlet 2.5 -


I got this small code snippet from one of my JSP files:

  & lt; C: When test = "$ {not empty param ['filePath'] '& amp; amp; amp; amp; amp; amp; amp; amp; เคจเคนीं; & Lt; C: Out value = "$ {sessionScope.fileHelper.getContentsForPath (param.filePath, param.revision)}" escapeXml = "incorrect" /> & Lt; / C: When & gt;  

Unfortunately I have to migrate back to servlet 2.5 , I was currently using 3.0 .

The problem with this, that EL (Expression Language) does not support calling methods like this in earlier versions. So I asked me how to complete the same thing with 2.5 compatible code.

fileHelper is added to sessionScope as a separate JSP file:

 < Code> & lt; Jsp: useBean id = "fileHelper" class = "de.myPackage.util.FileHelper" scope = "session" />  

What I tried was:

  & lt;% @ page import = "de.myPackage.util.FileHelper"%> & Lt; C: when test = "$ {not empty param ['filePath'] & amp; amp; amp; amp; not; ['Amendment']}>>  "EscapeXml =" false "/> & lt; / c: when & gt;  

but it does not work after writing:

The method is undefined for getContentsForPath (string, string) object type.

Any ideas?

You () to the cast session object .getContentsForPath () to use it. Something like this:

  (FileHelper) session.getAttribute ("fileHelper"). GetContentsForPath (...)  

No comments:

Post a Comment