Home > database >  How to pass a large string variable in jsp without any alteration?
How to pass a large string variable in jsp without any alteration?

Time:02-11

I'm in a need to obtain a data from the backend and it will be assigned to local variables through JSP in the front-end. The actual string data coming from backend is below:

"{\"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\"}]}"

I'm using JSP to assign it to a local variable as below:

var diffOutputList = '<c:out value="${diffResponse.diffOutputList}"/>'

After this when I'm printing the diffOutputList in the console, it is printing like below:

{&#034;deltas&#034;:[{&#034;source&#034;:{&#034;position&#034;:63,&#034;lines&#034;:[]},&#034;target&#034;:{&#034;position&#034;:65,&#034;lines&#034;:[&#034;return {&#034;]},&#034;type&#034;:&#034;INSERT&#034;},{&#034;source&#034;:{&#034;position&#034;:57,&#034;lines&#034;:[&#034;//comment one&#034;,&#034;//comment two&#034;,&#034;//comment three&#034;]},&#034;target&#034;:{&#034;position&#034;:62,&#034;lines&#034;:[]},&#034;type&#034;:&#034;DELETE&#034;},{&#034;source&#034;:{&#034;position&#034;:53,&#034;lines&#034;:[&#034;&#034;]},&#034;target&#034;:{&#034;position&#034;:56,&#034;lines&#034;:[&#034;version.open(options,endpoint, false);&#034;,&#034;version.send(payload);&#034;,&#034;result = version.responseE4X;&#034;]},&#034;type&#034;:&#034;CHANGE&#034;},{&#034;source&#034;:{&#034;position&#034;:44,&#034;lines&#034;:[]},&#034;target&#034;:{&#034;position&#034;:44,&#034;lines&#034;:[&#034;            &#034;&lt;sch:status&gt;&#034; status &#034;&lt;/sch:status&gt;&#034; &#034;,&#034;            &#034;&lt;sch:workflowExternalRef&gt;&#034; refId &#034;&lt;/sch:workflowExternalRef&gt;&#034; &#034;,&#034;            &#034;&lt;sch:description&gt;&#034; description &#034;&lt;/sch:description&gt;&#034;  &#034;]},&#034;type&#034;:&#034;INSERT&#034;},{&#034;source&#034;:{&#034;position&#034;:42,&#034;lines&#034;:[&#034;} else if(taskType==&#034;registration&#034;){&#034;]},&#034;target&#034;:{&#034;position&#034;:42,&#034;lines&#034;:[&#034;} else if(taskType==&#034;appRegistration&#034;){&#034;]},&#034;type&#034;:&#034;CHANGE&#034;},{&#034;source&#034;:{&#034;position&#034;:35,&#034;lines&#034;:[&#034;} else if(taskType==&#034;app&#034;){&#034;]},&#034;target&#034;:{&#034;position&#034;:35,&#034;lines&#034;:[&#034;} else if(taskType==&#034;application&#034;){&#034;]},&#034;type&#034;:&#034;CHANGE&#034;},{&#034;source&#034;:{&#034;position&#034;:28,&#034;lines&#034;:[&#034;} else if(taskType==&#034;signup&#034;){&#034;]},&#034;target&#034;:{&#034;position&#034;:28,&#034;lines&#034;:[&#034;} else if(taskType==&#034;user-signup&#034;){&#034;]},&#034;type&#034;:&#034;CHANGE&#034;},{&#034;source&#034;:{&#034;position&#034;:14,&#034;lines&#034;:[&#034;                              { name : &#034;&#034;, value :cookie },&#034;]},&#034;target&#034;:{&#034;position&#034;:14,&#034;lines&#034;:[&#034;                              { name : &#034;Cookie&#034;, value :cookie },&#034;]},&#034;type&#034;:&#034;CHANGE&#034;},{&#034;source&#034;:{&#034;position&#034;:11,&#034;lines&#034;:[&#034;var cookie=session.get(&#034;&#034;);&#034;]},&#034;target&#034;:{&#034;position&#034;:11,&#034;lines&#034;:[&#034;var cookie=session.get(&#034;workflowCookie&#034;);&#034;]},&#034;type&#034;:&#034;CHANGE&#034;}]}

But I need the string in the below format:

'{"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":["            \\"&lt;sch:status&gt;\\" status \\"&lt;/sch:status&gt;\\" ","            \\"&lt;sch:workflowExternalRef&gt;\\" refId \\"&lt;/sch:workflowExternalRef&gt;\\" ","            \\"&lt;sch:description&gt;\\" description \\"&lt;/sch:description&gt;\\"  "]},"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"}]}'

CodePudding user response:

c:out automatically escapes XML tags in the rendering. The escaping replaces " by &#034;.

You can disable the escaping with the escapeXml parameter:

var diffOutputList = '<c:out escapeXml="false" value="${diffResponse.diffOutputList}" />'

But in this case, c:out is not really necessary, you could use:

var diffOutputList = '${diffResponse.diffOutputList}'
  • Related