这是不起作用的代码片段:
<%@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", "/")}
非常感谢您对我的问题提出任何建议,谢谢。
最佳答案
您正在尝试将老式 scriptlet 与现代 EL 混合在一起。这是行不通的。 EL 在页面、请求、 session 和应用程序范围中搜索变量作为属性。它根本不搜索在(全局)scriptlet 范围中声明的变量。
为了为 EL 准备变量,您需要将其设置为所需范围内的属性。通常,您会为此使用 Servlet 或过滤器,或者可能是请求/ session /上下文监听器,但为了快速原型(prototype)设计,您可能仍然希望使用老式的 scriptlet。下面是一个将其放入请求范围的示例:
<%
String[] strings = { "happy", "in 7th heaven", "on cloud 8" };
request.setAttribute("strings", strings);
%>
另请参阅:
关于java - JSTL 函数 fn :split and fn:join are not functioning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15627247/