JSTL Split方法无法正常工作?

时间:2016-12-29 09:44:04

标签: split jstl jstl-functions

我正在尝试使用JSTL方法拆分字符串,并在四个引号''''的基础上拆分它。以下是详细信息:

example = ''''THE FAMOUS DIAMONDS''''This is second string for the example''''/content/dam/rcq/mp_push_tank_style.jpg''''right''''
${fn:split(example,\"''''\")}
example[0]=THE FAMOUS DIAMONDS
example[1]=This is second string for the example
example[2]=/content/dam/abc/tank.jpg
example[3]=right

对于上面提到的字符串,它工作正常,但问题是我的字符串中它们是'(single quote)并且它的功能会中断。以下是示例

example = ''''THE FAMOUS DIAMONDS''''This is  string's contains single quote''''/content/dam/rcq/mp_push_tank_style.jpg''''right''''
${fn:split(example,\"''''\")}
example[0]=THE FAMOUS DIAMONDS
example[1]=This is  string
example[2]=s contains single quote
example[3]=/content/dam/abc/tank.jpg

现在您看到示例[2]包含文本而不是imagepath。

任何人都可以提供帮助,因为我无法更改拆分类型''''

提前致谢

1 个答案:

答案 0 :(得分:0)

jstl-function fn:split()中存在使用 apostrophe 的问题,而不是您可以使用scriptlet,其中拆分将完美运行。我在这里为你做过:

<c:set var="string1" value="''''THE FAMOUS DIAMONDS''''This is  string's contains single quote''''/content/dam/rcq/mp_push_tank_style.jpg''''right''''"/>
<%
    String s=(String)pageContext.getAttribute("string1");
    String[] string = s.split("''''");
    pageContext.setAttribute("string",string);
 %>
<c:set var="string2" value="${string}"/>
<p>String(0) : ${string2[0]}</p>
<p>String(1) : ${string2[1]}</p>
<p>String(2) : ${string2[2]}</p>
<p>String(3) : ${string2[3]}</p>
<p>String(4) : ${string2[4]}</p>

输出:

String(0) :
String(1) : THE FAMOUS DIAMONDS
String(2) : This is string's contains single quote
String(3) : /content/dam/rcq/mp_push_tank_style.jpg
String(4) : right
相关问题