【问题标题】:Escape XML tags in textarea在 textarea 中转义 XML 标签
【发布时间】:2016-10-19 07:21:08
【问题描述】:

我正在使用 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>">

任何帮助将不胜感激..

【问题讨论】:

    标签: java xml jsp spring-boot escaping


    【解决方案1】:
    <textarea name="txtXml" rows="45" cols="223">${fileContent}</textarea>
    

    【讨论】:

    • 当我申请尝试您的更新时,textarea 变为空。
    • @NewBeeDeveloper 检查更新 2 )))
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多