Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Calling pageContext methods with EL

843840Sep 23 2007 — edited Sep 25 2007
I'm a java developer that has done some JSPs but not super familiar with the latest JSTL/EL technologies, but I'm learning.

I have a straight forward question with a problem I'm having and then a more generic design question.

First the problem question ... I'd like to (indirectly) call some methods from pageContext using the EL, but when I try something like this[*]:

${pageContext.servletContext.realPath("/")}

I get this error:

"The function realPath must be used with a prefix when a default namespace is not specified"

The only solution I could come up with is to do this (which works):

<%
pageContext.setAttribute("path", pageContext.getServletContext().getRealPath("/"));
%>
${pageScope.path}

Is this the only way to do this?

In a related question, when defining EL functions, do you have any access to the JSP environment (e.g. pageContext, implicit maps, etc ...)?

Finally, my design question ... I'd like to essentially write my own directory lister. It seems I'd need to use at least the ServletContext.getRealPath() function and use a File object to get the directory listings.

My first thought is to create a custom tag, but then I'd likely need to use a lot of out.write(). My next thought is to use an EL function, but I don't think it has access to the JSP environment (e.g. pageContext, implicit maps, etc ...), does it? And then there's tag files, jsp fragments, and probably lots more .. it's a bit overwhelming. Any suggestions?

The environment here isn't important, but just to state it, I'm using java 1.5 on a mac with tomcat 6.

Thanks!




[*] - sorry, it isn't clear how to insert code blocks ... shouldn't it be obvious?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 23 2007
Added on Sep 23 2007
6 comments
405 views