-6ren">
gpt4 book ai didi

java - 在文本区域中转义 XML 标签

转载 作者:行者123 更新时间:2023-12-01 09:21:50 25 4
gpt4 key购买 nike

我正在使用 jsp 进行 spring boot,其中我需要在 jsp 文本区域中显示 XML 字符串。我在显示 XML 时遇到了一个奇怪的问题。第一个标签刚刚被撕掉,并在末尾添加了一个额外的 ">

Note.xml

<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

greetings.jsp

<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<title>Hello</title>
</head>
<body>
<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>
</form>
</body>
</html>

IndexController.java

    @Controller
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) {
System.out.println(e.getMessage());
}

return "greeting";
}
}

输出

<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>">

任何帮助将不胜感激..

最佳答案

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

关于java - 在文本区域中转义 XML 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40124737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com