NewBee Developer NewBee Developer - 11 months ago 87
Java Question

Escape XML tags in textarea

I am working on spring boot with jsp in which I have a requirement to show an XML string in a jsp textarea. I ran into a strange problem while displaying the XML. The first tag just got ripped off and an extra

added at the end


<?xml version="1.0" encoding="UTF-8"?>
<body>Don't forget me this weekend!</body>


<!DOCTYPE html>

<meta charset="UTF-8">
<form action="/smartxml/openxml" method="POST" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="Open" name="btnOpen" /><br/><br/>
<textarea name="txtXml" rows="45" cols="223" value="${fileContent}"></textarea>

public class IndexController {
@RequestMapping(params = "btnOpen", method = RequestMethod.POST)
public String uploadFile(@RequestParam("file") MultipartFile file, Model model) {
try {
InputStream is = file.getInputStream();
StringWriter writer = new StringWriter();
IOUtils.copy(is, writer, StandardCharsets.UTF_8);
String fileContent = writer.toString();
model.addAttribute("fileContent", xmlOperation.readXml(is));
} catch (IOException e) {

return "greeting";


<body>Don't forget me this weekend!</body>

Any help would be appreciated..

Answer Source
<textarea name="txtXml" rows="45" cols="223">${fileContent}</textarea>