如何在 jsp 中传递一个大字符串变量而不进行任何更改?
How to pass a large string variable in jsp without any alteration?
我需要从后台获取一个数据,在前台通过JSP赋值给局部变量。来自后端的实际字符串数据如下:
"{\"deltas\":[{\"source\":{\"position\":63,\"lines\":[]},\"target\":{\"position\":65,\"lines\":[\"return {\"]},\"type\":\"INSERT\"},{\"source\":{\"position\":57,\"lines\":[\"//comment one\",\"//comment two\",\"//comment three\"]},\"target\":{\"position\":62,\"lines\":[]},\"type\":\"DELETE\"},{\"source\":{\"position\":53,\"lines\":[\"\"]},\"target\":{\"position\":56,\"lines\":[\"version.open(options,endpoint, false);\",\"version.send(payload);\",\"result \= version.responseE4X;\"]},\"type\":\"CHANGE\"},{\"source\":{\"position\":44,\"lines\":[]},\"target\":{\"position\":44,\"lines\":[\" \\"\<sch:status\>\\"+status+\\"\</sch:status\>\\"+\",\" \\"\<sch:workflowExternalRef\>\\"+refId+\\"\</sch:workflowExternalRef\>\\"+\",\" \\"\<sch:description\>\\"+description+\\"\</sch:description\>\\" +\"]},\"type\":\"INSERT\"},{\"source\":{\"position\":42,\"lines\":[\"} else if(taskType\=\=\\"registration\\"){\"]},\"target\":{\"position\":42,\"lines\":[\"} else if(taskType\=\=\\"appRegistration\\"){\"]},\"type\":\"CHANGE\"},{\"source\":{\"position\":35,\"lines\":[\"} else if(taskType\=\=\\"app\\"){\"]},\"target\":{\"position\":35,\"lines\":[\"} else if(taskType\=\=\\"application\\"){\"]},\"type\":\"CHANGE\"},{\"source\":{\"position\":28,\"lines\":[\"} else if(taskType\=\=\\"signup\\"){\"]},\"target\":{\"position\":28,\"lines\":[\"} else if(taskType\=\=\\"user-signup\\"){\"]},\"type\":\"CHANGE\"},{\"source\":{\"position\":14,\"lines\":[\" { name : \\"\\", value :cookie },\"]},\"target\":{\"position\":14,\"lines\":[\" { name : \\"Cookie\\", value :cookie },\"]},\"type\":\"CHANGE\"},{\"source\":{\"position\":11,\"lines\":[\"var cookie\=session.get(\\"\\");\"]},\"target\":{\"position\":11,\"lines\":[\"var cookie\=session.get(\\"workflowCookie\\");\"]},\"type\":\"CHANGE\"}]}"
我正在使用 JSP 将其分配给如下局部变量:
var diffOutputList = '<c:out value="${diffResponse.diffOutputList}"/>'
在此之后,当我在控制台中打印 diffOutputList 时,打印如下:
{"deltas":[{"source":{"position":63,"lines":[]},"target":{"position":65,"lines":["return {"]},"type":"INSERT"},{"source":{"position":57,"lines":["//comment one","//comment two","//comment three"]},"target":{"position":62,"lines":[]},"type":"DELETE"},{"source":{"position":53,"lines":[""]},"target":{"position":56,"lines":["version.open(options,endpoint, false);","version.send(payload);","result = version.responseE4X;"]},"type":"CHANGE"},{"source":{"position":44,"lines":[]},"target":{"position":44,"lines":[" "<sch:status>"+status+"</sch:status>"+"," "<sch:workflowExternalRef>"+refId+"</sch:workflowExternalRef>"+"," "<sch:description>"+description+"</sch:description>" +"]},"type":"INSERT"},{"source":{"position":42,"lines":["} else if(taskType=="registration"){"]},"target":{"position":42,"lines":["} else if(taskType=="appRegistration"){"]},"type":"CHANGE"},{"source":{"position":35,"lines":["} else if(taskType=="app"){"]},"target":{"position":35,"lines":["} else if(taskType=="application"){"]},"type":"CHANGE"},{"source":{"position":28,"lines":["} else if(taskType=="signup"){"]},"target":{"position":28,"lines":["} else if(taskType=="user-signup"){"]},"type":"CHANGE"},{"source":{"position":14,"lines":[" { name : "", value :cookie },"]},"target":{"position":14,"lines":[" { name : "Cookie", value :cookie },"]},"type":"CHANGE"},{"source":{"position":11,"lines":["var cookie=session.get("");"]},"target":{"position":11,"lines":["var cookie=session.get("workflowCookie");"]},"type":"CHANGE"}]}
但我需要以下格式的字符串:
'{"deltas":[{"source":{"position":63,"lines":[]},"target":{"position":65,"lines":["return {"]},"type":"INSERT"},{"source":{"position":57,"lines":["//comment one","//comment two","//comment three"]},"target":{"position":62,"lines":[]},"type":"DELETE"},{"source":{"position":53,"lines":[""]},"target":{"position":56,"lines":["version.open(options,endpoint, false);","version.send(payload);","result = version.responseE4X;"]},"type":"CHANGE"},{"source":{"position":44,"lines":[]},"target":{"position":44,"lines":[" \"<sch:status>\"+status+\"</sch:status>\"+"," \"<sch:workflowExternalRef>\"+refId+\"</sch:workflowExternalRef>\"+"," \"<sch:description>\"+description+\"</sch:description>\" +"]},"type":"INSERT"},{"source":{"position":42,"lines":["} else if(taskType==\"registration\"){"]},"target":{"position":42,"lines":["} else if(taskType==\"appRegistration\"){"]},"type":"CHANGE"},{"source":{"position":35,"lines":["} else if(taskType==\"app\"){"]},"target":{"position":35,"lines":["} else if(taskType==\"application\"){"]},"type":"CHANGE"},{"source":{"position":28,"lines":["} else if(taskType==\"signup\"){"]},"target":{"position":28,"lines":["} else if(taskType==\"user-signup\"){"]},"type":"CHANGE"},{"source":{"position":14,"lines":[" { name : \"\", value :cookie },"]},"target":{"position":14,"lines":[" { name : \"Cookie\", value :cookie },"]},"type":"CHANGE"},{"source":{"position":11,"lines":["var cookie=session.get(\"\");"]},"target":{"position":11,"lines":["var cookie=session.get(\"workflowCookie\");"]},"type":"CHANGE"}]}'
c:out
自动转义渲染中的 XML 标签。转义将 "
替换为 "
.
您可以使用 escapeXml
参数禁用转义:
var diffOutputList = '<c:out escapeXml="false" value="${diffResponse.diffOutputList}" />'
但在这种情况下,c:out
并不是必需的,您可以使用:
var diffOutputList = '${diffResponse.diffOutputList}'
我需要从后台获取一个数据,在前台通过JSP赋值给局部变量。来自后端的实际字符串数据如下:
"{\"deltas\":[{\"source\":{\"position\":63,\"lines\":[]},\"target\":{\"position\":65,\"lines\":[\"return {\"]},\"type\":\"INSERT\"},{\"source\":{\"position\":57,\"lines\":[\"//comment one\",\"//comment two\",\"//comment three\"]},\"target\":{\"position\":62,\"lines\":[]},\"type\":\"DELETE\"},{\"source\":{\"position\":53,\"lines\":[\"\"]},\"target\":{\"position\":56,\"lines\":[\"version.open(options,endpoint, false);\",\"version.send(payload);\",\"result \= version.responseE4X;\"]},\"type\":\"CHANGE\"},{\"source\":{\"position\":44,\"lines\":[]},\"target\":{\"position\":44,\"lines\":[\" \\"\<sch:status\>\\"+status+\\"\</sch:status\>\\"+\",\" \\"\<sch:workflowExternalRef\>\\"+refId+\\"\</sch:workflowExternalRef\>\\"+\",\" \\"\<sch:description\>\\"+description+\\"\</sch:description\>\\" +\"]},\"type\":\"INSERT\"},{\"source\":{\"position\":42,\"lines\":[\"} else if(taskType\=\=\\"registration\\"){\"]},\"target\":{\"position\":42,\"lines\":[\"} else if(taskType\=\=\\"appRegistration\\"){\"]},\"type\":\"CHANGE\"},{\"source\":{\"position\":35,\"lines\":[\"} else if(taskType\=\=\\"app\\"){\"]},\"target\":{\"position\":35,\"lines\":[\"} else if(taskType\=\=\\"application\\"){\"]},\"type\":\"CHANGE\"},{\"source\":{\"position\":28,\"lines\":[\"} else if(taskType\=\=\\"signup\\"){\"]},\"target\":{\"position\":28,\"lines\":[\"} else if(taskType\=\=\\"user-signup\\"){\"]},\"type\":\"CHANGE\"},{\"source\":{\"position\":14,\"lines\":[\" { name : \\"\\", value :cookie },\"]},\"target\":{\"position\":14,\"lines\":[\" { name : \\"Cookie\\", value :cookie },\"]},\"type\":\"CHANGE\"},{\"source\":{\"position\":11,\"lines\":[\"var cookie\=session.get(\\"\\");\"]},\"target\":{\"position\":11,\"lines\":[\"var cookie\=session.get(\\"workflowCookie\\");\"]},\"type\":\"CHANGE\"}]}"
我正在使用 JSP 将其分配给如下局部变量:
var diffOutputList = '<c:out value="${diffResponse.diffOutputList}"/>'
在此之后,当我在控制台中打印 diffOutputList 时,打印如下:
{"deltas":[{"source":{"position":63,"lines":[]},"target":{"position":65,"lines":["return {"]},"type":"INSERT"},{"source":{"position":57,"lines":["//comment one","//comment two","//comment three"]},"target":{"position":62,"lines":[]},"type":"DELETE"},{"source":{"position":53,"lines":[""]},"target":{"position":56,"lines":["version.open(options,endpoint, false);","version.send(payload);","result = version.responseE4X;"]},"type":"CHANGE"},{"source":{"position":44,"lines":[]},"target":{"position":44,"lines":[" "<sch:status>"+status+"</sch:status>"+"," "<sch:workflowExternalRef>"+refId+"</sch:workflowExternalRef>"+"," "<sch:description>"+description+"</sch:description>" +"]},"type":"INSERT"},{"source":{"position":42,"lines":["} else if(taskType=="registration"){"]},"target":{"position":42,"lines":["} else if(taskType=="appRegistration"){"]},"type":"CHANGE"},{"source":{"position":35,"lines":["} else if(taskType=="app"){"]},"target":{"position":35,"lines":["} else if(taskType=="application"){"]},"type":"CHANGE"},{"source":{"position":28,"lines":["} else if(taskType=="signup"){"]},"target":{"position":28,"lines":["} else if(taskType=="user-signup"){"]},"type":"CHANGE"},{"source":{"position":14,"lines":[" { name : "", value :cookie },"]},"target":{"position":14,"lines":[" { name : "Cookie", value :cookie },"]},"type":"CHANGE"},{"source":{"position":11,"lines":["var cookie=session.get("");"]},"target":{"position":11,"lines":["var cookie=session.get("workflowCookie");"]},"type":"CHANGE"}]}
但我需要以下格式的字符串:
'{"deltas":[{"source":{"position":63,"lines":[]},"target":{"position":65,"lines":["return {"]},"type":"INSERT"},{"source":{"position":57,"lines":["//comment one","//comment two","//comment three"]},"target":{"position":62,"lines":[]},"type":"DELETE"},{"source":{"position":53,"lines":[""]},"target":{"position":56,"lines":["version.open(options,endpoint, false);","version.send(payload);","result = version.responseE4X;"]},"type":"CHANGE"},{"source":{"position":44,"lines":[]},"target":{"position":44,"lines":[" \"<sch:status>\"+status+\"</sch:status>\"+"," \"<sch:workflowExternalRef>\"+refId+\"</sch:workflowExternalRef>\"+"," \"<sch:description>\"+description+\"</sch:description>\" +"]},"type":"INSERT"},{"source":{"position":42,"lines":["} else if(taskType==\"registration\"){"]},"target":{"position":42,"lines":["} else if(taskType==\"appRegistration\"){"]},"type":"CHANGE"},{"source":{"position":35,"lines":["} else if(taskType==\"app\"){"]},"target":{"position":35,"lines":["} else if(taskType==\"application\"){"]},"type":"CHANGE"},{"source":{"position":28,"lines":["} else if(taskType==\"signup\"){"]},"target":{"position":28,"lines":["} else if(taskType==\"user-signup\"){"]},"type":"CHANGE"},{"source":{"position":14,"lines":[" { name : \"\", value :cookie },"]},"target":{"position":14,"lines":[" { name : \"Cookie\", value :cookie },"]},"type":"CHANGE"},{"source":{"position":11,"lines":["var cookie=session.get(\"\");"]},"target":{"position":11,"lines":["var cookie=session.get(\"workflowCookie\");"]},"type":"CHANGE"}]}'
c:out
自动转义渲染中的 XML 标签。转义将 "
替换为 "
.
您可以使用 escapeXml
参数禁用转义:
var diffOutputList = '<c:out escapeXml="false" value="${diffResponse.diffOutputList}" />'
但在这种情况下,c:out
并不是必需的,您可以使用:
var diffOutputList = '${diffResponse.diffOutputList}'