gpt4 book ai didi

jsp - pretty-print JSON 输出

转载 作者:行者123 更新时间:2023-11-28 23:47:31 24 4
gpt4 key购买 nike

我有以下jsp

 <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" 
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns="http://www.w3.org/1999/xhtml"
version="2.0">

<jsp:directive.page contentType="text/html" pageEncoding="UTF-8" />
<jsp:output omit-xml-declaration="true" />
<jsp:output doctype-root-element="html" doctype-system="about:legacy-compat"/>

<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>HTML5</title>
</head>
<body>
<h1>HTML5</h1>
</body>
</html>

</jsp:root>

默认tomcat7生成的html是这样的

<!DOCTYPE html SYSTEM "about:legacy-compat">
<html lang="en"><head><meta content="text/html; charset=utf-8" http-equiv="content-type"/><title>HTML5</title></head><body><h1>HTML5</h1></body></html>

我希望它被打印出来(只是为了调试更好)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta name="generator" content=
"HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" />
<meta content="text/html; charset=us-ascii" http-equiv="content-type" />

<title>HTML5</title>
</head>

<body>
<h1>HTML5</h1>
</body>

我想如果我编写与 html 相同的页面并将其命名为 jsp,它会保留它的格式并且我仍然可以使用 jsp tage。

最佳答案

您遇到的问题是您使用的是 JSP 的 XML 版本,而不是典型的 JSP。这就是为什么你所有的空白都被消耗掉了。

您可以转换为普通的 JSP,或者您可以添加一个过滤器来使用全部内容,然后重新格式化它。后者并非微不足道,但也不是 super 困难。

关于jsp - pretty-print JSON 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12548160/

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