JSP trimDirectiveWhitespaces [英] JSP trimDirectiveWhitespaces

查看:147
本文介绍了JSP trimDirectiveWhitespaces的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试几种改善和减少响应大小,网络流量和加载时间的方法. 我想使用的一件事是trimDirectiveWhitespaces元素. 我将其放在page指令中:

I am testing several ways to improve and reduce my response size, network traffic, and load time. One of the things I thought of using is the trimDirectiveWhitespaces element. I placed it in the page directive:

<%@ page contentType="text/html;charset=UTF-8" language="java" trimDirectiveWhitespaces="true"%> 

我添加了一些空的新行,但在响应中没有看到任何变化,或者当我查看文档源时,那里有新行.

I added some empty new lines and didn't see any change in my response or when i view source of the document, new lines were there.

此方法的正确用法是什么?我在做什么错了?

What is the correct usage of this and what am I doing wrong?

推荐答案

trimDirectiveWhitespaces 仅删除JSP标记周围的空行,并保留其他空行.

trimDirectiveWhitespaces only removes empty lines around JSP tags and leaves other empty lines as they are.

示例:

<% page pageEncoding="UTF-8"%>X
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>X
<html>


<head>

它将变为:

X
X
<html>


<head>

(请注意,在此示例中,我添加了X来标记行尾,因此更明显,并且stackoverflow不会将其修剪掉)

(note I added X to mark end-of-line for this example, so it is more obvious and stackoverflow wont trim them out)

如果在page指令中添加了trimDirectiveWhitespaces="true",则输出将变为:

If trimDirectiveWhitespaces="true" is added to the page directive, the output becomes:

<html>


<head>

删除了前两行,但保留了后两行(在htmlhead标记之间).

The first two empty lines are removed, but the next two (between the html and head tags) are preserved.

这篇关于JSP trimDirectiveWhitespaces的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆