1

Here's the snippet of code that is not working :

<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%! String[] strings = {"happy","in 7th heaven","on cloud 8"}; %>
${fn:join(strings , '&')}
${fn:split("some/word/goes/here", "/")}

Any flash put into my question is far appreciated, thanks ahead .

Rehme
  • 323
  • 3
  • 6
  • 20

1 Answers1

1

You're trying to mix mixing oldschool scriptlets with modern EL. This is not going to work. EL searches for variables as attributes in page, request, session and application scopes. It does not search for variables declared in (global) scriptlet scope at all.

In order to prepare variables for EL, you need to set it as an attribute in the desired scope. Normally, you'd use a servlet or filter for this, or maybe a request/session/context listener, but for quick prototyping you might still want to use an old fashioned scriptlet. Here's an example which puts it in the request scope:

<%
    String[] strings = { "happy", "in 7th heaven", "on cloud 8" };
    request.setAttribute("strings", strings);
%>

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • oh, forgot that EL searches only for scoped attributes, but fn:split still not working, It prints [Ljava.lang.String;@13f57b3 instead, thanks – Rehme Mar 26 '13 at 01:50
  • 1
    What did you expect then? Do you get a different result when you print a `String[]` in a normal Java class with a `main()` method? You'd normally just loop over it and print the individual items. In JSP you can do the same using ``. – BalusC Mar 26 '13 at 02:12
  • Yes, I know. Did you understand me? The `fn:split()` returns a `String[]` and this kind of printout is fully expected for object arrays. – BalusC Mar 26 '13 at 02:39
  • My mistake, Now everything sorted out, Thank you sir ! – Rehme Mar 26 '13 at 02:52