我有以下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。
答案 0 :(得分:0)
您遇到的问题是您使用的是XML版本的JSP,而不是典型的JSP。这就是为什么你的所有空白都被消耗掉了。
您可以转换为普通JSP,也可以添加使用整个内容的过滤器,然后重新格式化。后者不是微不足道的,但也不是特别困难。