[英]Escape XML tags in textarea
我正在使用jsp進行春季啟動,其中我需要在jsp textarea中顯示XML字符串。 顯示XML時遇到一個奇怪的問題。 剛剛撕下第一個標簽,並在末尾添加了一個額外的">
注意.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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.