java - Adding new line in string in JSP -


i'm trying pass string request attribute jsp. reuqest.setattriute("string", xml);

the string comes xml file parsed using following code:

document doc = dbuilder.parse(fxmlfile);     domimplementationls domimplementation = (domimplementationls) doc.getimplementation(); lsserializer lsserializer = domimplementation.createlsserializer(); string string= lsserializer.writetostring(doc); 

when put string on console, can see nice formatted output (exactly in xml file, new lines kept).

when i'm trying display string in jsp, observe not formatted code, string not tarnsform new line signs.

this code jsp:

i trying use fn:replace function, did not work (i trying transform 'a' latter instead of '\n' tests ommit problems special characters). can see <br /> tags in displayed string not transformed new lines.

<c:set var="string2" value='${fn:replace(string, "a", "<br />")}' /> 

when displaying string2, if displaying using jstl, think are, need set escapexml attribute false explicitly. becasue default jstl escapexml attribute true, render tags such <br/> in plain text format. while displaying string in jsp, use below

<c:out value="${string}" escapexml="false" /> 

this interpret br tags in string line breaks


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -