Java 如何在JSP页面中显示漂亮的打印JSON字符串

Java 如何在JSP页面中显示漂亮的打印JSON字符串,java,json,jsp,spring-mvc,jackson,Java,Json,Jsp,Spring Mvc,Jackson,我想在JSP页面中显示JSON字符串。我正在使用SpringMVC框架。下面是代码 String result = restTemplate.getForObject(url.toString(), String.class); ObjectMapper mapper = new ObjectMapper(); Object json = mapper.readValue(result, Object.class); String indented = mapper.defaultPrett

我想在JSP页面中显示JSON字符串。我正在使用SpringMVC框架。下面是代码

String result = restTemplate.getForObject(url.toString(), String.class);

ObjectMapper mapper = new ObjectMapper();
Object json = mapper.readValue(result, Object.class);

String indented = mapper.defaultPrettyPrintingWriter().writeValueAsString(json);

System.out.println(indented);//This print statement show correct way I need

model.addAttribute("response", (indented));
此行
System.out.println(缩进)打印出如下内容-

{
  "attributes" : [ {
    "nm" : "ACCOUNT",
    "error" : "null SYS00019CancellationException in CoreImpl fetchAttributes\n java.util.concurrent.CancellationException\n\tat java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:231)\n\tat java.util.concurrent.FutureTask.",
    "status" : "ERROR"
  } ]
}
model.addAttribute("response", (indented));
这是我需要使用JSP页面显示的方式。但当我把它添加到这样的模型中时-

{
  "attributes" : [ {
    "nm" : "ACCOUNT",
    "error" : "null SYS00019CancellationException in CoreImpl fetchAttributes\n java.util.concurrent.CancellationException\n\tat java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:231)\n\tat java.util.concurrent.FutureTask.",
    "status" : "ERROR"
  } ]
}
model.addAttribute("response", (indented));
然后在resultform.jsp页面中显示它,如下所示-

    <fieldset>
        <legend>Response:</legend>
            <strong>${response}</strong><br />

    </fieldset>
我不需要。我不知道为什么要这样包装?我需要它打印出来的方式,就像这样

{
  "attributes" : [ {
    "nm" : "ACCOUNT",
    "error" : "null SYS00019CancellationException in CoreImpl fetchAttributes\n java.util.concurrent.CancellationException\n\tat java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:231)\n\tat java.util.concurrent.FutureTask.",
    "status" : "ERROR"
  } ]
}
谁能告诉我为什么会这样?如何在JSP页面中以我需要的方式显示它?

这些字符包括换行符。将JSON转储到文件中


${response}
其他解决方案:

此类字符包括换行符。将JSON转储到文件中


${response}

其他解决方案:

非常感谢Matt。这正是我想要的。非常感谢马特。这正是我想要的。