2016-12-29 42 views
-1

我想分割一個字符串使用JSTL方法,並分裂它的基礎上四個報價''''。以下是詳細內容: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)和它的功能GET休息。下面是示例

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]包含文本而不是圖像路徑。

任何人都可以幫忙,因爲我不能改變拆分類型''''

在此先感謝

回答

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